added error checking
added error checking (corrected)