Code optimizations and modifications