Some slight optimization of surface.py.