refactor intermediate