fixed redirect loop bug