fixes many bugs, all tests look good