refactor, add template support, not backward compatible