Better toClassObject method