Added some comments
Added more comment and formatted code