Fix AssertionError

Fixes 2 logic problems. Works for me.