Custom clustering implementation