initial refactor of mainService.js