refactor logic out of controllers into services