Corrected main update loop