separate out error checking code