Refactor MODE logic