Adding unit tests. Fixed minor issues