Merge refactored code into repaired branch