Updated comments and tidied code