ground-up recode, actually works now