Fix bugs for earlier change.
Re-organize mode hierarchy.
Implement exit/quit command properly.