CFY-769 lots of code optimizations