Refactoring legacy applications