fixing id selection in visualize() function