Various small fixes and tidy-ups
Code reformat