Move viewformat function into global factory