refactoring and added a cancel button to the alert