added random pivot selection, added helper methods