Added tests, README, did some refactoring