better redirect handling