Refactored to use factory