Fix a bug for redirection and clean some useless code