Updated the redirect function