refactor and document print-example code