Tidy up and comment code.