optimize for-loop