refactor using template