Fix minor issue of where clause disappearing after a number of joins