Photoshop

Im having a few problems with some duplicating commands. Here is a sample of part of a script to transfer layers and layer sets between docs. It works fine if all the sets are at the top of the doc but errors on layer sets after layers not sure what I have got wrong here. Also won’t let me duplicate layer sets into layer sets should this be possible? does anybody have sample of syntax for duplicate path items the reference says this is supported but I can’t get it to work. thanks

tell application "Adobe Photoshop CS"
	set docRef to current document
	tell docRef
		set LayerCount to count every layer of docRef
		get name of every layer of docRef
		get name of every layer set of docRef

		repeat with i from 1 to LayerCount
			get properties of layer i
			set LayerName to get name of layer i of docRef

			if class of layer i = layer set then
				duplicate layer set i to before layer "Layer 1" of ¬
					(document "TestFile.psd" of application "Adobe Photoshop CS") with properties {name:LayerName}
			end if
			if class of layer i = art layer then
				duplicate layer i to before layer "Layer 1" of ¬
					(document "TestFile.psd" of application "Adobe Photoshop CS") with properties {name:LayerName}
			end if
		delay 3
	end repeat
	end tell
end tell