Add checking for undef template value. It is not neccessary to set template after the last action.