Remove unnecessary steps in the algorithm and cleanup