Major refactoring.
Merge pull request #5 from mpath/working

Major refactoring.