finished refactoring the join phase