add templates and simplify interface of painter