refactor into a class and factory method