various code optimizations