Merge refactor branch back to master