A bit more refactoring and generalising.
Minor changes.
Minor formatting changes. Added a readme.