Latest working code (morning of Jan. 7).