Use templates in core to avoid fatals

Bug: 73377
Change-Id: I5a956864d86bbf8cea40cdd1015636e675d8e778