mid refactor