Fix redirect function