add comments
adjust some code to reduce indentions