moved redirect code