Added smarter version of naive that only sorts when it needs to