Added comments and improved flow of program