Micro-optimizations and code cleanup