Swaped order of statements in the main loop. (optimized code)