Index: uspace/app/init/init.c
===================================================================
--- uspace/app/init/init.c	(revision ab1861a5bb6566e9af17508d7a742f847c7c75d1)
+++ uspace/app/init/init.c	(revision 402de0c55e1244d9577ac32ddd4be299249808be)
@@ -89,10 +89,6 @@
 	argv[1] = NULL;
 	
-	if (task_spawn(fname, argv)) {
-		/* Add reasonable delay to avoid intermixed klog output. */
-		usleep(10000);
-	} else {
+	if (!task_spawn(fname, argv))
 		printf(NAME ": Error spawning %s\n", fname);
-	}
 }
 
Index: uspace/app/tetris/input.c
===================================================================
--- uspace/app/tetris/input.c	(revision ab1861a5bb6566e9af17508d7a742f847c7c75d1)
+++ uspace/app/tetris/input.c	(revision 402de0c55e1244d9577ac32ddd4be299249808be)
@@ -116,5 +116,5 @@
 again:
 		if (!getchar_inprog) {
-			cons_phone = console_phone_get(true);
+			cons_phone = console_open(true);
 			getchar_inprog = async_send_2(cons_phone,
 			    CONSOLE_GETKEY, 0, 0, &charcall);
Index: uspace/lib/libc/generic/console.c
===================================================================
--- uspace/lib/libc/generic/console.c	(revision ab1861a5bb6566e9af17508d7a742f847c7c75d1)
+++ uspace/lib/libc/generic/console.c	(revision 402de0c55e1244d9577ac32ddd4be299249808be)
@@ -33,6 +33,7 @@
  */
 /** @file
- */ 
-
+ */
+
+#include <libc.h>
 #include <async.h>
 #include <io/stream.h>
@@ -46,5 +47,5 @@
 
 /** Size of cbuffer. */
-#define CBUFFER_SIZE 256
+#define CBUFFER_SIZE  256
 
 /** Buffer for writing characters to the console. */
@@ -57,26 +58,92 @@
 static char *cbp = cbuffer;
 
-static ssize_t cons_write(const char *buf, size_t nbyte);
-static void cons_putchar(wchar_t c);
-
-static void cbuffer_flush(void);
-static void cbuffer_drain(void);
-static inline void cbuffer_putc(int c);
-
-
-void console_open(bool blocking)
+
+/** Write one character to the console via IPC. */
+static void cons_putchar(wchar_t c)
+{
+	console_wait();
+	async_msg_1(console_phone, CONSOLE_PUTCHAR, c);
+}
+
+/** Write characters to the console via IPC or to klog */
+static ssize_t cons_write(const char *buf, size_t size)
+{
+	console_open(false);
+	
+	if (console_phone >= 0) {
+		async_serialize_start();
+		
+		ipc_call_t answer;
+		aid_t req = async_send_0(console_phone, CONSOLE_WRITE, &answer);
+		ipcarg_t rc = ipc_data_write_start(console_phone, (void *) buf, size);
+		
+		if (rc != EOK) {
+			async_wait_for(req, NULL);
+			async_serialize_end();
+			return (ssize_t) rc;
+		}
+		
+		async_wait_for(req, &rc);
+		async_serialize_end();
+		
+		if (rc == EOK)
+			return (ssize_t) IPC_GET_ARG1(answer);
+		else
+			return -1;
+	} else
+		return __SYSCALL3(SYS_KLOG, 1, (sysarg_t) buf, size);
+}
+
+/** Write all data from output buffer to the console. */
+static void cbuffer_flush(void)
+{
+	size_t len = cbp - cbuffer;
+	
+	while (len > 0) {
+		ssize_t rc = cons_write(cbuffer, cbp - cbuffer);
+		if (rc < 0)
+			return;
+		
+		len -= rc;
+	}
+	
+	cbp = cbuffer;
+}
+
+/** Drop all data in console output buffer. */
+static void cbuffer_drain(void)
+{
+	cbp = cbuffer;
+}
+
+/** Write one character to the output buffer. */
+static inline void cbuffer_putc(char c)
+{
+	if (cbp == cbuffer_end)
+		cbuffer_flush();
+	
+	*cbp++ = c;
+	
+	if (c == '\n')
+		cbuffer_flush();
+}
+
+int console_open(bool blocking)
 {
 	if (console_phone < 0) {
 		int phone;
-		if (blocking) {
+		
+		if (blocking)
 			phone = ipc_connect_me_to_blocking(PHONE_NS,
 			    SERVICE_CONSOLE, 0, 0);
-		} else {
-			phone = ipc_connect_me_to(PHONE_NS, SERVICE_CONSOLE, 0,
-			    0);
-		}
+		else
+			phone = ipc_connect_me_to(PHONE_NS,
+			    SERVICE_CONSOLE, 0, 0);
+		
 		if (phone >= 0)
 			console_phone = phone;
 	}
+	
+	return console_phone;
 }
 
@@ -84,16 +151,7 @@
 {
 	if (console_phone >= 0) {
-		if (ipc_hangup(console_phone) == 0) {
+		if (ipc_hangup(console_phone) == 0)
 			console_phone = -1;
-		}
-	}
-}
-
-int console_phone_get(bool blocking)
-{
-	if (console_phone < 0)
-		console_open(blocking);
-	
-	return console_phone;
+	}
 }
 
@@ -106,195 +164,109 @@
 void console_clear(void)
 {
-	int cons_phone = console_phone_get(true);
-
+	console_wait();
 	cbuffer_drain();
-	async_msg_0(cons_phone, CONSOLE_CLEAR);
+	async_msg_0(console_phone, CONSOLE_CLEAR);
+}
+
+int console_get_size(int *rows, int *cols)
+{
+	console_wait();
+	
+	ipcarg_t r;
+	ipcarg_t c;
+	int rc = async_req_0_2(console_phone, CONSOLE_GETSIZE, &r, &c);
+	
+	*rows = (int) r;
+	*cols = (int) c;
+	
+	return rc;
+}
+
+void console_set_style(int style)
+{
+	console_wait();
+	cbuffer_flush();
+	async_msg_1(console_phone, CONSOLE_SET_STYLE, style);
+}
+
+void console_set_color(int fg_color, int bg_color, int flags)
+{
+	console_wait();
+	cbuffer_flush();
+	async_msg_3(console_phone, CONSOLE_SET_COLOR, fg_color, bg_color, flags);
+}
+
+void console_set_rgb_color(int fg_color, int bg_color)
+{
+	console_wait();
+	cbuffer_flush();
+	async_msg_2(console_phone, CONSOLE_SET_RGB_COLOR, fg_color, bg_color);
+}
+
+void console_cursor_visibility(int show)
+{
+	console_wait();
+	cbuffer_flush();
+	async_msg_1(console_phone, CONSOLE_CURSOR_VISIBILITY, show != 0);
+}
+
+void console_kcon_enable(void)
+{
+	console_wait();
+	cbuffer_flush();
+	async_msg_0(console_phone, CONSOLE_KCON_ENABLE);
 }
 
 void console_goto(int row, int col)
 {
-	int cons_phone = console_phone_get(true);
-
-	cbuffer_flush();
-	async_msg_2(cons_phone, CONSOLE_GOTO, row, col);
+	console_wait();
+	cbuffer_flush();
+	async_msg_2(console_phone, CONSOLE_GOTO, row, col);
 }
 
 void console_putchar(wchar_t c)
 {
-//	cbuffer_putc(c);
+	console_wait();
 	cbuffer_flush();
 	cons_putchar(c);
 }
 
-/** Write all data from output buffer to the console. */
-static void cbuffer_flush(void)
-{
-	int rc;
-	int len;
-
-	len = cbp - cbuffer;
-
-	while (len > 0) {
-		rc = cons_write(cbuffer, cbp - cbuffer);
-		if (rc < 0)
-			return;
-
-		len -= rc;
-	}
-
-	cbp = cbuffer;
-}
-
-/** Drop all data in console output buffer. */
-static void cbuffer_drain(void)
-{
-	cbp = cbuffer;
-}
-
-/** Write one character to the output buffer. */
-static inline void cbuffer_putc(int c)
-{
-	if (cbp == cbuffer_end)
-		cbuffer_flush();
-
-	*cbp++ = c;
-
-	if (c == '\n')
-		cbuffer_flush();
-}
-
-/** Write one character to the console via IPC. */
-static void cons_putchar(wchar_t c)
-{
-	int cons_phone = console_phone_get(true);
-	async_msg_1(cons_phone, CONSOLE_PUTCHAR, c);
-}
-
-/** Write characters to the console via IPC. */
-static ssize_t cons_write(const char *buf, size_t nbyte) 
-{
-	int cons_phone = console_phone_get(true);
-	ipcarg_t rc;
-	ipc_call_t answer;
-	aid_t req;
-
-	async_serialize_start();
-	
-	req = async_send_0(cons_phone, CONSOLE_WRITE, &answer);
-	rc = ipc_data_write_start(cons_phone, (void *) buf, nbyte);
-
-	if (rc != EOK) {
-		async_wait_for(req, NULL);
-		async_serialize_end();
-		return (ssize_t) rc;
-	}
-
-	async_wait_for(req, &rc);
-	async_serialize_end();
-
-	if (rc == EOK)
-		return (ssize_t) IPC_GET_ARG1(answer);
-	else
-		return -1;
-}
-
 /** Write characters to the console. */
-ssize_t console_write(const char *buf, size_t nbyte) 
-{
-	size_t left;
-
-	left = nbyte;
-
+ssize_t console_write(const char *buf, size_t size)
+{
+	size_t left = size;
+	
 	while (left > 0) {
 		cbuffer_putc(*buf++);
-		--left;
-	}
-
-	return nbyte;
+		left--;
+	}
+	
+	return size;
 }
 
 /** Write a NULL-terminated string to the console. */
-void console_putstr(const char *s)
-{
-	size_t len;
-	ssize_t rc;
-
-	len = str_size(s);
-	while (len > 0) {
-		rc = console_write(s, len);
-		if (rc < 0)
-			return; /* Error */
-		s += rc;
-		len -= rc;
-	}
-}
-
-/** Flush all output to the console. */
+void console_putstr(const char *str)
+{
+	size_t left = str_size(str);
+	
+	while (left > 0) {
+		ssize_t rc = console_write(str, left);
+		
+		if (rc < 0) {
+			/* Error */
+			return;
+		}
+		
+		str += rc;
+		left -= rc;
+	}
+}
+
+/** Flush all output to the console or klog. */
 void console_flush(void)
 {
-	int cons_phone = console_phone_get(false);
-
-	cbuffer_flush();
-	async_msg_0(cons_phone, CONSOLE_FLUSH);
-}
-
-void console_flush_optional(void)
-{
+	cbuffer_flush();
 	if (console_phone >= 0)
-		console_flush();
-}
-
-int console_get_size(int *rows, int *cols)
-{
-	int cons_phone = console_phone_get(true);
-	ipcarg_t r, c;
-	int rc;
-
-	rc = async_req_0_2(cons_phone, CONSOLE_GETSIZE, &r, &c);
-
-	*rows = (int) r;
-	*cols = (int) c;
-
-	return rc;
-}
-
-void console_set_style(int style)
-{
-	int cons_phone = console_phone_get(true);
-
-	cbuffer_flush();
-	async_msg_1(cons_phone, CONSOLE_SET_STYLE, style);
-}
-
-void console_set_color(int fg_color, int bg_color, int flags)
-{
-	int cons_phone = console_phone_get(true);
-
-	cbuffer_flush();
-	async_msg_3(cons_phone, CONSOLE_SET_COLOR, fg_color, bg_color, flags);
-}
-
-void console_set_rgb_color(int fg_color, int bg_color)
-{
-	int cons_phone = console_phone_get(true);
-
-	cbuffer_flush();
-	async_msg_2(cons_phone, CONSOLE_SET_RGB_COLOR, fg_color, bg_color);
-}
-
-void console_cursor_visibility(int show)
-{
-	int cons_phone = console_phone_get(true);
-
-	cbuffer_flush();
-	async_msg_1(cons_phone, CONSOLE_CURSOR_VISIBILITY, show != 0);
-}
-
-void console_kcon_enable(void)
-{
-	int cons_phone = console_phone_get(true);
-
-	cbuffer_flush();
-	async_msg_0(cons_phone, CONSOLE_KCON_ENABLE);
+		async_msg_0(console_phone, CONSOLE_FLUSH);
 }
 
Index: uspace/lib/libc/generic/io/io.c
===================================================================
--- uspace/lib/libc/generic/io/io.c	(revision ab1861a5bb6566e9af17508d7a742f847c7c75d1)
+++ uspace/lib/libc/generic/io/io.c	(revision 402de0c55e1244d9577ac32ddd4be299249808be)
@@ -39,4 +39,5 @@
 #include <string.h>
 #include <errno.h>
+#include <console.h>
 
 const static char nl = '\n';
@@ -50,6 +51,7 @@
 	
 	for (count = 0; str[count] != 0; count++);
-	if (write_stdout((void *) str, count) == count) {
-		if (write_stdout(&nl, 1) == 1)
+	
+	if (console_write((void *) str, count) == count) {
+		if (console_write(&nl, 1) == 1)
 			return 0;
 	}
@@ -65,5 +67,5 @@
 int putnchars(const char *buf, size_t count)
 {
-	if (write_stdout((void *) buf, count) == count)
+	if (console_write((void *) buf, count) == count)
 		return 0;
 	
@@ -82,5 +84,5 @@
 
 	for (count = 0; str[count] != 0; count++);
-	if (write_stdout((void *) str, count) == count)
+	if (console_write((void *) str, count) == count)
 		return 0;
 	
@@ -97,5 +99,5 @@
 		return EOF;
 
-	if (write_stdout((void *) buf, offs) == offs)
+	if (console_write((void *) buf, offs) == offs)
 		return c;
 
@@ -106,6 +108,6 @@
 {
 	unsigned char c;
-
-	flush_stdout();
+	
+	console_flush();
 	if (read_stdin((void *) &c, 1) == 1)
 		return c;
@@ -116,6 +118,8 @@
 int fflush(FILE *f)
 {
+	/* Dummy implementation */
 	(void) f;
-	return flush_stdout();
+	console_flush();
+	return 0;
 }
 
Index: uspace/lib/libc/generic/io/stream.c
===================================================================
--- uspace/lib/libc/generic/io/stream.c	(revision ab1861a5bb6566e9af17508d7a742f847c7c75d1)
+++ uspace/lib/libc/generic/io/stream.c	(revision 402de0c55e1244d9577ac32ddd4be299249808be)
@@ -50,18 +50,13 @@
 #include <sys/types.h>
 
-ssize_t write_stderr(const void *buf, size_t count)
-{
-	return count;
-}
-
 ssize_t read_stdin(void *buf, size_t count)
 {
-	int cons_phone = console_phone_get(false);
-
+	int cons_phone = console_open(false);
+	
 	if (cons_phone >= 0) {
 		kbd_event_t ev;
 		int rc;
 		size_t i = 0;
-	
+		
 		while (i < count) {
 			do {
@@ -69,39 +64,10 @@
 				if (rc < 0) return -1;
 			} while (ev.c == 0 || ev.type == KE_RELEASE);
-
+			
 			((char *) buf)[i++] = ev.c;
 		}
 		return i;
-	} else {
+	} else
 		return -1;
-	}
-}
-
-ssize_t write_stdout(const void *buf, size_t count)
-{
-	int cons_phone = console_phone_get(false);
-	int left, rc;
-
-	if (cons_phone >= 0) {
-		int i;
-
-		left = count;
-		while (left > 0) {
-			rc = console_write(buf, left);
-			if (rc < 0)
-				break;
-			buf += rc;
-			left -= rc;
-		}
-
-		return count;
-	} else
-		return __SYSCALL3(SYS_KLOG, 1, (sysarg_t) buf, count);
-}
-
-int flush_stdout(void)
-{
-	console_flush();
-	return 0;
 }
 
Index: uspace/lib/libc/generic/io/vprintf.c
===================================================================
--- uspace/lib/libc/generic/io/vprintf.c	(revision ab1861a5bb6566e9af17508d7a742f847c7c75d1)
+++ uspace/lib/libc/generic/io/vprintf.c	(revision 402de0c55e1244d9577ac32ddd4be299249808be)
@@ -39,4 +39,5 @@
 #include <futex.h>
 #include <async.h>
+#include <console.h>
 
 static atomic_t printf_futex = FUTEX_INITIALIZER;
@@ -51,5 +52,5 @@
 		prev = offset;
 		str_decode(str, &offset, size);
-		write_stdout(str + prev, offset - prev);
+		console_write(str + prev, offset - prev);
 		chars++;
 	}
@@ -68,5 +69,5 @@
 		boff = 0;
 		chr_encode(str[chars], buf, &boff, 4);
-		write_stdout(buf, boff);
+		console_write(buf, boff);
 		chars++;
 		offset += sizeof(wchar_t);
Index: uspace/lib/libc/generic/kbd.c
===================================================================
--- uspace/lib/libc/generic/kbd.c	(revision ab1861a5bb6566e9af17508d7a742f847c7c75d1)
+++ uspace/lib/libc/generic/kbd.c	(revision 402de0c55e1244d9577ac32ddd4be299249808be)
@@ -43,5 +43,5 @@
 int kbd_get_event(kbd_event_t *ev)
 {
-	int cons_phone = console_phone_get(true);
+	int cons_phone = console_open(true);
 	ipcarg_t r0, r1, r2, r3;
 	int rc;
Index: uspace/lib/libc/generic/libc.c
===================================================================
--- uspace/lib/libc/generic/libc.c	(revision ab1861a5bb6566e9af17508d7a742f847c7c75d1)
+++ uspace/lib/libc/generic/libc.c	(revision 402de0c55e1244d9577ac32ddd4be299249808be)
@@ -85,5 +85,5 @@
 
 	main(argc, argv);
-	console_flush_optional();
+	console_flush();
 }
 
Index: uspace/lib/libc/include/console.h
===================================================================
--- uspace/lib/libc/include/console.h	(revision ab1861a5bb6566e9af17508d7a742f847c7c75d1)
+++ uspace/lib/libc/include/console.h	(revision 402de0c55e1244d9577ac32ddd4be299249808be)
@@ -28,5 +28,5 @@
 
 /** @addtogroup libc
- * @{ 
+ * @{
  */
 /** @file
@@ -41,8 +41,6 @@
 #include <bool.h>
 
-extern void console_open(bool);
+extern int console_open(bool);
 extern void console_close(void);
-
-extern int console_phone_get(bool);
 extern void console_wait(void);
 
@@ -50,8 +48,7 @@
 extern void console_goto(int, int);
 extern void console_putchar(wchar_t);
-extern ssize_t console_write(const char *buf, size_t nbyte);
-extern void console_putstr(const char *s);
+extern ssize_t console_write(const char *, size_t);
+extern void console_putstr(const char *);
 extern void console_flush(void);
-extern void console_flush_optional(void);
 
 extern int console_get_size(int *, int *);
@@ -64,5 +61,5 @@
 
 #endif
- 
+
 /** @}
  */
Index: uspace/lib/libc/include/io/stream.h
===================================================================
--- uspace/lib/libc/include/io/stream.h	(revision ab1861a5bb6566e9af17508d7a742f847c7c75d1)
+++ uspace/lib/libc/include/io/stream.h	(revision 402de0c55e1244d9577ac32ddd4be299249808be)
@@ -38,12 +38,8 @@
 #include <libarch/types.h>
 
-#define EMFILE -17
-
-extern void klog_update(void);
+#define EMFILE  -17
 
 extern ssize_t read_stdin(void *, size_t);
-extern ssize_t write_stdout(const void *, size_t);
-extern ssize_t write_stderr(const void *, size_t);
-extern int flush_stdout(void);
+extern void klog_update(void);
 
 #endif
