Added decorator and abstracted the main redirection code