Main loop editied