Problem with javascript LiveAPI

Cphas's icon

I'm writing a clip launcher in javascript for and M4L device I'm working on. It works fine except when I quit Live which causes it to "crash". By that I mean that OS X comes up with a message saying that Live quit unexpectedly. I've narrowed it down to the javascript; removing it means this problem does not occur. Can anyone offer any suggestions as to why this might be happening? I've attached the code, many thanks in advance.

ClipLaunch.js
js