Added type checking before assigning value to object.