Code refactoring under constraints