Handle deletes and some refactoring