implementation of remove function.