REfactor logic in completion controller