optimize the template method.