correct handling of the history file, now its writing will be performed only ad the end of the execution of the shell
little code refactoring