Implemented choosePivot subroutine