Fixing main loop