Merge pull request #229 from nhr/ha_tweaked

Fixed typo
Trying to make more flexible template logic
Merge pull request #230 from nhr/array_protection

Array protection