Generic code optimizations