Added tests, fixed bug.