Moved recursive delete to its own function