updated error checking