Added tests, fixed bugs etc.