Refactor to polymorphic pattern