fixed a bug on optional args detection
tidied up template doms