modified remove function