improved deletion logic