moved main functions out of routes file