Fixed infinite loop bugs in the visualization code.