Various cleanups and mild refactoring, in preparation to push upstream.
Removed SExprRef.
Removed index from branches.
Removed backendID from SExpr -- just use the normal id.