Style nit:  Given that the above if success returns, then fall-through into the else occurs only if we have more work to do.  It is much more readable to read code written as:

  if (condition1)
    return result;

  try something else
  if (condition2)
    return result;

  try something else
  if (condition3)
    return result;

  fail

Than it is to read:

  if (condition1) {
    return result;
  } else {
    try something else
    if (condition2) {
      return result;
    } else {
      if (condition3) {
        return result;
      } else {
        fail
      }
    }
  }