moved all functions from route file, here.