Cleaning up common code in intermediate steps