replace join with reduce