Fix color bug
Prepare to introduce some cache
Fix bug in previous commit
Caching. Optimizing pivot choice only early.