Revert "Remove unneeded optimizations"

This reverts commit 49fed2c9ca72f28d64d21f3b36a3c5421503141d.