Fixed minor bugs. Added asserts