refactor code for pretty-printer