add patterns/templates support
refactoring
doc fix