Modified kd-tree to use spatial median heuristic for speed, added I/O timing, modified refraction to work with triangle meshes