Change map function signatures to return errors and write alloced tmpl to out