added comments and more explanations