added allbutsmallest and sort functions