Enhancements to retrieve the number of clients

also little refactorings