Organising files and folder paths

I have written the script posted here to try to group files and folder into their containing path. What I hope to get at the end is:

{{“volume:mainfolder:folder:subfolder”, “file.ext”, “file2.ext”, “file3.ext”}, {“volume:mainfolder:folder”, “subfolder”, “subfolder2”, “file4.ext”, “file5.ext”}}

but what I get is:
{{“volume:mainfolder:folder:subfolder”, “file.ext”, “file2.ext”, “file3.ext”}, {“volume:mainfolder:folder”, “subfolder”, “subfolder2”, “file4.ext”, “file5.ext”}, {“volume:mainfolder:folder”, “subfolder2”}, {“volume:mainfolder:folder”, “file4.ext”}, {“volume:mainfolder:folder”, “file5.ext”}}

Ultimately I will provide a full path with a list of files or folders under it like so:
afp://volume/mainfolder/folder/subfolder
file.ext
file2.ext
file3.ext

afp://volume/mainfolder/folder
subfolder
subfolder2
file4.ext
file5.ext

I can see my logic is faulty and I might be going about this in a very clumsy way. Any help appreciated.

set pathsAndNames to {¬
	"volume:mainfolder:folder:subfolder:file.ext", ¬
	"volume:mainfolder:folder:subfolder", ¬
	"volume:mainfolder:folder:subfolder2", ¬
	"volume:mainfolder:folder:subfolder:file2.ext", ¬
	"volume:mainfolder:folder:subfolder:file3.ext", ¬
	"volume:mainfolder:folder:file4.ext", ¬
	"volume:mainfolder:folder:file5.ext"}

set orderedList to {}

repeat with i from 1 to count of pathsAndNames
	set thisItem to item i of pathsAndNames
	set AppleScript's text item delimiters to ":"
	set thisItemContainer to (text items 1 through -2 of thisItem) as string
	set thisItemName to (text items -1 through -1 of thisItem) as string
	set AppleScript's text item delimiters to ""
	log thisItemContainer
	log thisItemName
	
	-- this is the bit that is going wrong
	if (count of orderedList) is not 0 then
		repeat with x from 1 to count of orderedList
			if thisItemContainer is in item x of orderedList then
				set end of item x of orderedList to thisItemName
				exit repeat
			else
				set end of orderedList to {thisItemContainer, thisItemName}
			end if
		end repeat
	else
		set end of orderedList to {thisItemContainer, thisItemName}
	end if
end repeat
return orderedList

Model: MacBook Pro 2.7 GHz Core i7 16GB RAM
Browser: Safari 537.31
Operating System: Mac OS X (10.8)

Cracked it. But would still like to know if someone has a better method.

set pathsAndNames to {¬
	"volume:mainfolder:folder:subfolder:file.ext", ¬
	"volume:mainfolder:folder:subfolder", ¬
	"volume:mainfolder:folder:subfolder2", ¬
	"volume:mainfolder:folder:subfolder:file2.ext", ¬
	"volume:mainfolder:folder:subfolder:file3.ext", ¬
	"volume:mainfolder:folder:file4.ext", ¬
	"volume:mainfolder:folder:file5.ext"}

set orderedList to {}

repeat with i from 1 to count of pathsAndNames
	set thisItem to item i of pathsAndNames
	set AppleScript's text item delimiters to ":"
	set thisItemContainer to (text items 1 through -2 of thisItem) as string
	set thisItemName to (text items -1 through -1 of thisItem) as string
	set AppleScript's text item delimiters to ""
	log thisItemContainer
	log thisItemName
	
	set inList to false
	if (count of orderedList) is not 0 then
		-- loop through and check if the path has been added before
		repeat with x from 1 to count of orderedList
			if thisItemContainer is in item x of orderedList then
				-- add the name to the end of the list
				set end of item x of orderedList to thisItemName
				set inList to true
				exit repeat
			end if
		end repeat
		-- if the path is not in any items then add it
		if not inList then
			set end of orderedList to {thisItemContainer, thisItemName}
		end if
	else -- if there is nothing in the list then add first item to it
		set end of orderedList to {thisItemContainer, thisItemName}
	end if
end repeat
return orderedList

Model: MacBook Pro 2.7 GHz Core i7 16GB RAM
Browser: Safari 537.31
Operating System: Mac OS X (10.8)