add some assertions and debug output