fixed redirect function bugs