restrcuturized code and sane comments

main function has been cleaned up and made into using subroutines
Each step of the program has been commented, just like variable names and subroutine names, so that the program is more easily readable.
It also compiles with VC 2010 without warnings and errors