Tidied up code, added comments and updated README