Trouble with list of due dates per area of focus

Hi friends!

I’m trying to write a script that can return a single sorted list of all due dates per area of focus. I have managed to pull the due dates and sort them, but I’m stumbling on how to filter this through an area of focus without using tags. I prefer to use top level folders for each area of focus, with nested folders for associated horizon altitude levels.

the relevant line of code is this:
set the_tasks to (every flattened task where (due date ≠ missing value) and (completed = false) and (the_folders contains name of folder of containing project)

however, it snags when it reaches projects because projects do not have a containing project to them and i havent figured out how to reference the name of a folder that contains a specific project, or if that would even fix this issue. See below for copy of script. Thank you for any insight you might have!

Here is where I am so far…

property h_Prefix : "ⓗ "
property p_Prefix : "⒫ : "
property fp_Prefix : "PS "
property sf_Prefix : "SD "

tell application “OmniFocus”
tell default document

set the_folders to name of every flattened folder whose name begins with h_Prefix
set the_folder to first flattened folder whose name is (item 1 of (choose from list the_folders))
set the_folders to name of every flattened folder of the_folder
set the_tasks to (every flattened task where (due date ≠ missing value) and (completed = false) and (the_folders contains name of folder of containing project))

repeat with i from 1 to (count of the_tasks) - 1
repeat with j from i + 1 to count of the_tasks
if due date of item j of the_tasks < due date of item i of the_tasks then
set temp to item i of the_tasks
set item i of the_tasks to item j of the_tasks
set item j of the_tasks to temp
end if
end repeat
end repeat
set task_names to {}

repeat with a from 1 to length of the_tasks

set the_task to item a of the_tasks
set task_name to name of the_task
set task_due to due date of the_task
set task_names to task_names & task_name

end repeat

return task_names