Rewrote exception handling. IOErrors were masked in Python < 3.3.