Working isosurface function, slightly refactored