Revert "Revert "Small optimizations""

This reverts commit 31079c2deaac7a96df15224cefbb4a64edc3a573.