Bugfixes, writing tests
Wrote tests