implemented unit tests and fixed bugs