Another bit of fixes including a missing sub_template and removed some unsed globals

Signed-off-by: emanuele <emanuele45@gmail.com>