Improved error checking and associated python exceptions