private static List<String> splitTopLevel(String s, String separator) {
        int balance = 0;
        int[] balances = new int[s.length()];
        List<String> result = new ArrayList<String>();
        StringBuilder token = new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == '(') {
                balance++;
            }
            if (s.charAt(i) == ')') {
                balance--;
            }
            balances[i] = balance;
        }

        for (int i = 0; i < s.length(); i++) {
            if (s.substring(i).startsWith(separator) && balances[i] == 0) {
                result.add(token.toString());
                token = new StringBuilder();
                i += separator.length() - 1;
            } else {
                token.append(s.charAt(i));
            }
        }
        if (token.length() > 0) {
            result.add(token.toString());
        }
        return result;
    }