separate out error checking code
merge