Bug fix to redirect code