Moved redundent code into a function and fixed and unwanted string replace
Passed in the itemObject to the createObject function to be able to use the object in the function