Pull out seeming unrelated code from previous commit