refactor: extract join query