fixed a few bugs and refactored the tests