fixed main loop
fixed main loop