Added check for redirect loop