reorganized controller code into services and factories