improved commenting and order of the code