a working wrapper

the code pretty much works, supports splitting and combining, may
require some adjustments in terms of readability, comments, etc.