Refactor to better handle printing