Refactoring common code and handling patches with Index lines