add if-else clause around id assignment.