changed error checking