centralize error checking