Fixed main_loop