Code written over summer 2013 for Abhishek Nagaraj at M.I.T. Sloan