Added custom error handling and dup_template option