Refactored to use more of a factory pattern for increased flexibility and cleanliness of code