major restructuring, better encapsulation of modes