Improve join function to accept arrays