Updated and finalized join code.