optimized join, freed memory, working on running multiple trials