Final tidy up of the code.