pre-refactoring into factory pattern to simplify code