Refactor & cleanup of mode and added automatic history on mode selection