Rewrite gallery view code.