I appreciate the script but it's still too complicated. There is so much going on in the script that it would be impossible for me to narrow it down to one specific issue.
I think you may be expecting too much of $$identifier. All $$identifier does is stop a command from being executed if $$identifier is empty. It has no idea about events, other scripts, return/halt, etc.
If what you are saying is that an empty $$identifier is not stopping a command from being executed, or is incorrectly stopping a command, please show me the simplest possible script that reproduces this.