More refactoring of custom viewer.