Some loop optimizations