A bit of a tidy and made it a little more robust.
Merge pull request #1 from wolfeidau/master

Bit of tidy up and made a couple of things a little more robust.