comment and tidy up code.