ENH: Service layer refactoring and testing
ENH: refactoring and testing