Extract parsing the environment into a function

It was getting in the way of reading what the message handler did.
Merge pull request #63 from nb/extract-parsing-the-environment

Extract parsing the environment into a function