code from UCSD Research Summer 2012