Fix for infinite redirect loop bug. Keep an eye on this, as I'm still not completely satisfied with this solution.