Implementing unit tests, bugfixing