Fixed a bug in a join routine