Added asserts for checking whether the logic is functioning correctly.