performance improvements in inner loop