Optimize by reducing the number of join() calls