Refactored code (should now work with python 3 as well). Minor changes to README.