Fixed capture templates

* The template should be an array of lines, even if there is just one
  line, makes it simple to deal with. Refactored code around capturing.