Public version of surface.py, fixed term_index algorithm, fixed some unit tests