Modifed for loop to preincrement for compilers that don't optimize