renamed many variable. added many comments