fixed a few minor bugs plus added a sort of a unit test