Backported per-key from resubmission of assignment 1.