changed a bit of the logic behind redirect