Optimize loop a bit