basic extraction refactor driven by tests