Add comments to code and simplify