Refactoring. Starting work on benchmarking.
Merge in refactor from Sam Rose, fixes #1