fix #2 and also fix #10 and move the templating in directive