tweaked sort template