Improved error handling!

@tleach cc @kiril