optimized stats calcs, reduced run time, added local logic