refactoring middleend