cleaned up exceptions, python3 compatible (I hope)