refactoring of the code, added comments, added the confirm windows

refactoring of the code, added comments, added the confirm windows