Refactor completion detection.

Signed-off-by: yrammos <yannis.rammos@me.com>