major performance improvements. added granularity implementation