Optimized to make painters work in more situations