Changed the structure and added some comments