WIP (untested): refactored code to support both index and service layers.