Fix error checking to the right time