Fix some deprecated exception styles and performance improvements