Debug was in wrong place to put error detection