unifying mode code
improved mode/menu code