updated class factory code