some refactoring to work against db, not network