implement mode with clever algorithm