Rearranged and commented the code.