refactored api to support testing