move redirect code to separate module