factored a large xSplitBy function into module