Fix some bugs in em2d.py.