fixed and speed improvements in sim.py wrt memory shadowing