This code looks familiar. Does it make sense to refactor it out of wherever you copied from?