Revise program flow and cut extra code

Add comments to code

Clean variables obtained from super globals