Refactor a provided block of legacy code to improve its readability, testability, and adherence to object-oriented or functional design principles.