More bug fixes for subquries and joins