tried to fix some bugs wit unit tests