refactor redirection code

also delete code for cancel button