Improved error checking

...ecified