Added comments, small changes in program structure