refactored mode to fix On^2 issue