Refactoring the remove method