library/modes: added an initial implementation of modes, allowing for easy customization of control code