refactoring main script