Added template support to reduce possible redundancy and improve conciseness$
Fixed some bugs in sponate