Refactored handling of cancel button in nav bar