updates to support nested templates