Move services code to services.js file