Fix/code issues

Tidy up the code with various formatting corrections.