Revert "Revert "Error handling optimizations""

This reverts commit e1d86a3239f26b39d4184c8eba0a969b921b7b14.