Merge Rutger's pull request (with refactoring) to fix units in design matrix, and more