Added tests, and solved bugs (thanks to tests, yes)