This code is duplicated; should it be done in a template/view?