Tidied up code and comments. Updated README.