Refine logic and cut down on unnecessary code.