Optimized build-nested-set, refs #5667

- Also fixed a syntax error at a throw new sfException