Finally fixed this bug.

Now for templates.