Merge refactor branch into master

The refactor branch is now at a point where it can be merged into master for further development.