micro optimizations and fixes