added handling of redirects