Moved all functions from index.js to services.