better redirection handling