Fix thread race bug + provide possibility to subscribe to Cmd.terminal.write deferred (OMS-144)