Refactor deletion algorithm to highlight bug