Script isnt working, please advise!

I tried to build an applescript to work with preps for some auto imposing, here is what I came up with below:


-- drop the file onto the Applescript application
on open wFile
	
	-- check if job exists in Preps 5
	
	tell application "Preps 5"
		if exists front job then
			activate
			close front job saving ask
		end if
		if not (exists (front job)) then
			tell application "Preps 5"
				activate
				make new job
			end tell
		end if
		
		-- get path of sourcefile in order to save the pdf into the same folder 
		set basePath to (get path of sourcefile 1) as text
		set destFolder to my searchReplace(basePath, baseName, "")
		
		-- get trim size of job and autoselect spread sigs accordingly
		-- some of the more common sizes are built into the script
		-- additional sizes can be built into the script by copying and pasting 2 lines of code, and changing the trim size (in points) and template name 
		
		-- for smaller sizes, trim size will also determine which crop marks to add on cover wrap, using variable nSce
		-- for example, setting nSce to 1 will pick up page 1 of cropmark PDF, which is 5.375 x 8.375 spread size
		-- setting nSce to 0 means that there are no pre-made crop marks for that trim size, so none will be added
		
		
		set trimSize to get size of runlist page 1
		
		if trimSize = {horizontal:594.0, vertical:774.0} then
			autoselect signatures for the front job using template "  8.25 x 10.75 MDB"
			set nSce to "0"
			
			-- to build a new size into the script, begin copy-paste here 
		else if trimSize = {horizontal:612.0, vertical:792.0} then
			autoselect signatures for the front job using template "8.5 x 11 MDB"
			set nSce to "0"
			-- end copy-paste
			
			
		else if trimSize = {horizontal:603.0, vertical:783.0} then
			autoselect signatures for the front job using template " 8.375 x 10.875 MDB"
			set nSce to "0"
			
		else if trimSize = {horizontal:387.0, vertical:603.0} then
			autoselect signatures for the front job using template "5.375 x 8.375 MDB"
			set nSce to "1"
			
		else if trimSize = {horizontal:387.0, vertical:612.0} then
			autoselect signatures for the front job using template " 5.375 x 8.5 MDB.tpl"
			set nSce to "2"
			
		else if trimSize = {horizontal:378.0, vertical:594.0} then
			autoselect signatures for the front job using template "5.25 x 8.25 MDB"
			set nSce to "3"
			
		else if trimSize = {horizontal:396.0, vertical:612.0} then
			autoselect signatures for the front job using template "5.5 x 8.5 MDB.tpl"
			set nSce to "4"
			
		else if trimSize = {horizontal:522.0, vertical:612.0} then
			autoselect signatures for the front job using template "7.25 x 8.5 MDB"
			set nSce to "5"
			
		else if trimSize = {horizontal:522.0, vertical:630.0} then
			autoselect signatures for the front job using template "7.25 X 8.75 mdb"
			set nSce to "6"
			
		else if trimSize = {horizontal:540.0, vertical:612.0} then
			autoselect signatures for the front job using template "7.5 x 8.5 MDB"
			set nSce to "7"
			
		else if trimSize = {horizontal:540.0, vertical:630.0} then
			autoselect signatures for the front job using template "7.5 x 8.75 MDB"
			set nSce to "8"
			
		else if trimSize = {horizontal:540.0, vertical:648.0} then
			autoselect signatures for the front job using template " 7.5 x 9 MDB"
			set nSce to "9"
			
		else if trimSize = {horizontal:540.0, vertical:684.0} then
			autoselect signatures for the front job using template "7.5 x 9.5 MDB"
			set nSce to "10"
			
			-- if the trim size is not recognized, user is prompted to select a template from the Preps templates folder	
		else
			set templSource to (choose file with prompt "select an impositon template from the Preps folder for autoselect") as text
			set templName to my searchReplace(templSource, "Macintosh HD:Applications:Preps 5.3:Templates:", "")
			
			autoselect signatures for the front job using template templName
			set nSce to "0"
			
		end if
		
		-- displays warning if run list page count doesn't match template autoselect page count
		set numSigs to count signatures of the front job
		set sigPages to (numSigs * 4)
		
		if pCount ≠ sigPages then
			display dialog "Warning: The job layout contains more pages than the run list. Would you like to continue?"
		end if
		
		
		-- print to file (printer spread) PDF
		print the front job to device "AdobePDF 8.0" saving as PDF file saving in destFolder filename fileName
		
	end tell
	
	save document fileName
	
	
	-- bring Acrobat to the front, with friendly alert that the script is done
	activate
	display dialog "Imposition script complete"
end open