Fixing i increment in loop