Moving functions from util.js to services.