Added resort and delay to sorting function