Fix deletion-related bugs