added ability to use custom template and pattern