fixed a bug where templating was done after paint method executed