Remove duplicated join code