How to manage fragile legacy code?