Corrected redirect function