migrated more error checking out of functions and into return conditional