refactor and fixed auto join

refactor and fixed auto join