Merge in @WickyNilliams refactored code.