refactored code with dialogs at the activity level