General code tidy up