reintroduced set splitting code, code is very procedural.. would a refactor make it easier to follow?