Better and correct way to handle media blocks

I am sure this PR will make Zuji's template faster.