properly handle redirects