join code update

This is based on #161 by @chenghao-intel .