Eek! I've lost track of how deep this is.  Please really consider breaking this stuff up into more descrete operations inside functions and use exception-handling logic to trap expected problems.  There are many calls to <code>options.find()</code> and then some related action.  This is a good sign you could benefit from writing a simple class (data + actions).  Another idea is a simple function call helper like:  <code>options_if_else('find this', function_if, function_else)</code>.  But more than likely, using a class will be easier.