remove funtion refactored