optimize and refactor completions