The implementation of remove() function.