optimize reduce points algorithm