Substantial work on visualization and on PEM (fixes a mistake returning xdot instead of y for PEM).