Move error checking out