Added some asserts and checks at the beginnings of methods.
fixed failing tests.