extracted function from duplicate code in createObject()