fixed a bug in join function