Fixed applying template restricting dangerous functions

Closes #1728