better errors, code deduplication
Merge pull request #1 from fiatjaf/1069-better-errors-and-code-deduplication

better errors, a little code deduplication