Centralise constants and error messages.

This implements feedback from @matthewrmshin.