Format, clean-up and minor refactoring