Refact the surface optimize code