more thorough error checking