This code *really* needs to be in a model somewhere.