refactor to support code reuse