Refactor putchar