193 performance

Originally commited in 98b7c55cb8b8e39e4835b5dd4223fda55f519890.

Fixes performance issues in #193