Small optimizations on loops