Generalize render logic