tidy code and add some Comments

it works