Corrected to cover the case of recursive joins