Fixed redirect loop bug