Patch from Kevin Stefanik <kstef@mtppi.org> to do some more error checking for