Error handling was in the wrong place