fix scope of variables, add comments, put initialize in constructor