Fixed bugs in ex31.py