modified generate_candidates