Handled back and cancel buttons properly