rearranged things and added comments