refactor to add callback for testing