refactoring of the app script