adding some more error checking
Error checking