Fix more bugs in terminal_writestring