try/catch causes optimizer bailouts in v8 for the entire function.  factor out all this logic into a helper method to keep the scope of the try-catch as small as possible.