Render refactor (with couple of fixes)

This is a bad inline: it has if statements, and calls another function which is not inline.