fix the tests...and some bugs