Factor out a bunch of error checking