Add some comments & moved all from main to fuctions