refactoring encounter scripts, fixing waiting bug