tidy up code to make it more readable