I didn't test (or even try to build) this, but here's how you can cut out a lot of boilerplate.
Merge pull request #1 from jmcarthur/patch-1

Cut boilderplate