Further optimize greedy heuristic