Made some major changes

I extracted code out of the latex document.  

I also updated figures, and added a serial switch 
program