Add missing factory logic and tests