General code tidyup