restructured, revised var names, added inline comments