Slightly better logic on templates