Refactor code for prettyTable