Added tests, and got it working