changing entire code

Complete change of code with objects and making code more clear and understandable