clean up error checking code