added more error checking
more error checking