refactoring some more modes logic into modes.js