Backport to python 2.6
Merge pull request #2 from jrha/master

Backport to python 2.6 and a lot of restructuring