comment tidying and some code refactoring