code refactoring :
- function separations,
- replacing alert with app.showAlert