Made exception code more pythonic.