fix bugs in redirecting