Cleaning code with suggestions from Eli White