added error checking