refactor and support for unordered x variables