That script is considerably more complicated and I am running short on time tonight. I'm hoping that someone else will chime in. It can be done but it will involve the use of scheduleAfter() and counters to track number of presses as well as time since button was released.
To find out why things are failing, surround all your code including the body of functions with try/catch and log to the diagnostics log or print to system. This will hopefully help you move forward in the interim.