Redid algorithm for joins