script structure refactoring