Code tidying and comments