Refactor types and pretty-printing