refactor middle