Three way quick sort and fixes