add template example and fixed some bugs