optimize the iteration