Moved redirect code to function
Moved logic code to logic files