Fixed reading and writing messages from terminal.