some small optimizations in loop2 and loop3