Main loop