added error checking.