Merge pull request #2 from DavidS/master

This merges lermit's work and adds a few fixes of my own