improve template loading method