added asserts and changed comments