Code as I left it in AmpLab on 10/24/2014