Improved redirect handling