optimize the loop (a bit)