automatic redirecting, still has bugs