TO-Do replace nested for loop with join()