Rewrite an 11-line join function