WIP porting xbh.c