begin refactoring into client library