added logic for ignoring non-existent candidates
added logic for ignoring non-existent candidates