move logic out of routes