Fix template bugs & whitespace issues.