Changed post-increments in for loops to pre-increments.