Cleaned up comments and tidied up code