slightly better implementation that allows null template prefix