refactor common display, file I/O code