updated join function