made major analysis loop more pythonic