added the error checking