Minor tidy up and code reordering