bugs fixed, asserts added