moved sort out of loop call in arrToHash method