Moved join commands inside a different loop.