Tidied code and comments