Fixing logic for similar entries in quick sort