Fixed some bugs, added unit test project