Changes to the logical flow of the code & edited some comments