Pulled from existing code with some clean up. currently untested
Merge pull request #1 from RhysC/InitialCommit

Pulled from existing code with some clean up. currently untested