updated comments, tightened up code