Refactored some to use factory pattern.