change sort to support template