Maya, Add Shape to Transform Script Issue

I wrote this script that adds shapes to my control rig. It works great when I add shapes to bones but messes up the offset when I add shapes to transforms. If I run part 1 and then part 2 it works fine but it I run it all together it messes up. I have been poking at this problem on and off for a bit but I don’t understand what is happening here.

# part 1
items = cmds.ls(sl=1)
shape = cmds.listRelatives(items[0], shapes=1)
cmds.parent(shape, items[1], shape=1, absolute=1)
shapeParent = cmds.listRelatives(shape, parent=1)
cmds.makeIdentity(shapeParent, apply=True)
# part 2
cmds.parent(shape, items[1], shape=1, relative=1)
cmds.delete(items[0])
cmds.delete(shapeParent)

-Andrew