Refactoring

Please, check and report. Also  read the code for some coding hints.