Lots of code optimizations