using sorting function