fixed choosePivot subroutine