Tidy up code and add some comments.