refactored and fixed deletion