add template and fixed the bug