Index: uspace/app/bdsh/cmds/modules/ls/ls.c
===================================================================
--- uspace/app/bdsh/cmds/modules/ls/ls.c	(revision b3c185b62f0fa507e9d72bce104161ccdb4b3d57)
+++ uspace/app/bdsh/cmds/modules/ls/ls.c	(revision ecb7828095d2afcbe676486fada5cd94b53906da)
@@ -42,5 +42,5 @@
 #include <vfs/vfs.h>
 #include <str.h>
-#include <cap.h>
+#include <capa.h>
 
 #include "ls.h"
@@ -106,10 +106,10 @@
 		}
 
-		cap_spec_t cap;
-		cap_from_blocks(de->s.size, 1, &cap);
-		cap_simplify(&cap);
+		capa_spec_t capa;
+		capa_from_blocks(de->s.size, 1, &capa);
+		capa_simplify(&capa);
 
 		char *rptr;
-		errno_t rc = cap_format(&cap, &rptr);
+		errno_t rc = capa_format(&capa, &rptr);
 		if (rc != EOK) {
 			return rc;
Index: uspace/app/df/df.c
===================================================================
--- uspace/app/df/df.c	(revision b3c185b62f0fa507e9d72bce104161ccdb4b3d57)
+++ uspace/app/df/df.c	(revision ecb7828095d2afcbe676486fada5cd94b53906da)
@@ -35,5 +35,5 @@
  */
 
-#include <cap.h>
+#include <capa.h>
 #include <stdbool.h>
 #include <stdio.h>
@@ -124,9 +124,9 @@
 static errno_t size_to_human_readable(uint64_t nblocks, size_t block_size, char **rptr)
 {
-	cap_spec_t cap;
-
-	cap_from_blocks(nblocks, block_size, &cap);
-	cap_simplify(&cap);
-	return cap_format(&cap, rptr);
+	capa_spec_t capa;
+
+	capa_from_blocks(nblocks, block_size, &capa);
+	capa_simplify(&capa);
+	return capa_format(&capa, rptr);
 }
 
Index: uspace/app/fdisk/fdisk.c
===================================================================
--- uspace/app/fdisk/fdisk.c	(revision b3c185b62f0fa507e9d72bce104161ccdb4b3d57)
+++ uspace/app/fdisk/fdisk.c	(revision ecb7828095d2afcbe676486fada5cd94b53906da)
@@ -34,5 +34,5 @@
  */
 
-#include <cap.h>
+#include <capa.h>
 #include <errno.h>
 #include <fdisk.h>
@@ -136,7 +136,7 @@
 	nchoice_t *choice = NULL;
 	char *svcname = NULL;
-	cap_spec_t cap;
+	capa_spec_t capa;
 	fdisk_dev_info_t *sdev;
-	char *scap = NULL;
+	char *scapa = NULL;
 	char *dtext = NULL;
 	service_id_t svcid;
@@ -177,5 +177,5 @@
 		}
 
-		rc = fdisk_dev_info_capacity(info, &cap);
+		rc = fdisk_dev_info_capacity(info, &capa);
 		if (rc != EOK) {
 			printf("Error getting device capacity "
@@ -185,7 +185,7 @@
 		}
 
-		cap_simplify(&cap);
-
-		rc = cap_format(&cap, &scap);
+		capa_simplify(&capa);
+
+		rc = capa_format(&capa, &scapa);
 		if (rc != EOK) {
 			assert(rc == ENOMEM);
@@ -194,5 +194,5 @@
 		}
 
-		int ret = asprintf(&dtext, "%s (%s)", svcname, scap);
+		int ret = asprintf(&dtext, "%s (%s)", svcname, scapa);
 		if (ret < 0) {
 			rc = ENOMEM;
@@ -203,6 +203,6 @@
 		free(svcname);
 		svcname = NULL;
-		free(scap);
-		scap = NULL;
+		free(scapa);
+		scapa = NULL;
 
 		rc = nchoice_add(choice, dtext, info, 0);
@@ -261,5 +261,5 @@
 	free(dtext);
 	free(svcname);
-	free(scap);
+	free(scapa);
 	return rc;
 }
@@ -432,12 +432,12 @@
 	errno_t rc;
 	fdisk_part_spec_t pspec;
-	cap_spec_t cap;
-	cap_spec_t mcap;
+	capa_spec_t capa;
+	capa_spec_t mcapa;
 	vol_label_supp_t vlsupp;
 	vol_fstype_t fstype = 0;
 	tinput_t *tinput = NULL;
 	fdisk_spc_t spc;
-	char *scap;
-	char *smcap = NULL;
+	char *scapa;
+	char *smcapa = NULL;
 	char *label = NULL;
 	char *mountp = NULL;
@@ -448,5 +448,5 @@
 		spc = spc_pri;
 
-	rc = fdisk_part_get_max_avail(dev, spc, &mcap);
+	rc = fdisk_part_get_max_avail(dev, spc, &mcapa);
 	if (rc != EOK) {
 		rc = EIO;
@@ -454,7 +454,7 @@
 	}
 
-	cap_simplify(&mcap);
-
-	rc = cap_format(&mcap, &smcap);
+	capa_simplify(&mcapa);
+
+	rc = capa_format(&mcapa, &smcapa);
 	if (rc != EOK) {
 		rc = ENOMEM;
@@ -474,9 +474,9 @@
 	while (true) {
 		printf("Enter capacity of new partition.\n");
-		rc = tinput_read_i(tinput, smcap, &scap);
+		rc = tinput_read_i(tinput, smcapa, &scapa);
 		if (rc != EOK)
 			goto error;
 
-		rc = cap_parse(scap, &cap);
+		rc = capa_parse(scapa, &capa);
 		if (rc == EOK)
 			break;
@@ -485,6 +485,6 @@
 	tinput_destroy(tinput);
 	tinput = NULL;
-	free(smcap);
-	smcap = NULL;
+	free(smcapa);
+	smcapa = NULL;
 
 	if (pkind != lpk_extended) {
@@ -545,5 +545,5 @@
 
 	fdisk_pspec_init(&pspec);
-	pspec.capacity = cap;
+	pspec.capacity = capa;
 	pspec.pkind = pkind;
 	pspec.fstype = fstype;
@@ -561,5 +561,5 @@
 	return EOK;
 error:
-	free(smcap);
+	free(smcapa);
 	free(label);
 	free(mountp);
@@ -581,5 +581,5 @@
 	fdisk_part_t *part;
 	fdisk_part_info_t pinfo;
-	char *scap = NULL;
+	char *scapa = NULL;
 	char *spkind = NULL;
 	char *sfstype = NULL;
@@ -596,7 +596,7 @@
 		}
 
-		cap_simplify(&pinfo.capacity);
-
-		rc = cap_format(&pinfo.capacity, &scap);
+		capa_simplify(&pinfo.capacity);
+
+		rc = capa_format(&pinfo.capacity, &scapa);
 		if (rc != EOK) {
 			printf("Out of memory.\n");
@@ -623,5 +623,5 @@
 
 			int ret = asprintf(&sdesc, "%s %s, %s, %s", label,
-			    scap, spkind, sfstype);
+			    scapa, spkind, sfstype);
 			if (ret < 0) {
 				rc = ENOMEM;
@@ -630,5 +630,5 @@
 
 		} else {
-			int ret = asprintf(&sdesc, "%s, %s", scap, spkind);
+			int ret = asprintf(&sdesc, "%s, %s", scapa, spkind);
 			if (ret < 0) {
 				rc = ENOMEM;
@@ -644,6 +644,6 @@
 		}
 
-		free(scap);
-		scap = NULL;
+		free(scapa);
+		scapa = NULL;
 		free(spkind);
 		spkind = NULL;
@@ -658,5 +658,5 @@
 	return EOK;
 error:
-	free(scap);
+	free(scapa);
 	free(spkind);
 	free(sfstype);
@@ -907,11 +907,11 @@
 	fdisk_part_t *part;
 	fdisk_part_info_t pinfo;
-	cap_spec_t cap;
-	cap_spec_t mcap;
+	capa_spec_t capa;
+	capa_spec_t mcapa;
 	fdisk_dev_flags_t dflags;
 	char *sltype = NULL;
-	char *sdcap = NULL;
-	char *scap = NULL;
-	char *smcap = NULL;
+	char *sdcapa = NULL;
+	char *scapa = NULL;
+	char *smcapa = NULL;
 	char *sfstype = NULL;
 	char *svcname = NULL;
@@ -936,5 +936,5 @@
 	}
 
-	rc = fdisk_dev_capacity(dev, &cap);
+	rc = fdisk_dev_capacity(dev, &capa);
 	if (rc != EOK) {
 		printf("Error getting device capacity.\n");
@@ -942,7 +942,7 @@
 	}
 
-	cap_simplify(&cap);
-
-	rc = cap_format(&cap, &sdcap);
+	capa_simplify(&capa);
+
+	rc = capa_format(&capa, &sdcapa);
 	if (rc != EOK) {
 		printf("Out of memory.\n");
@@ -958,7 +958,7 @@
 	fdisk_dev_get_flags(dev, &dflags);
 
-	printf("Device: %s (%s)\n", svcname, sdcap);
-	free(sdcap);
-	sdcap = NULL;
+	printf("Device: %s (%s)\n", svcname, sdcapa);
+	free(sdcapa);
+	sdcapa = NULL;
 
 	rc = fdisk_label_get_info(dev, &linfo);
@@ -996,7 +996,7 @@
 		}
 
-		cap_simplify(&pinfo.capacity);
-
-		rc = cap_format(&pinfo.capacity, &scap);
+		capa_simplify(&pinfo.capacity);
+
+		rc = capa_format(&pinfo.capacity, &scapa);
 		if (rc != EOK) {
 			printf("Out of memory.\n");
@@ -1016,7 +1016,7 @@
 
 		if (linfo.ltype == lt_none)
-			printf("Entire disk: %s %s", label, scap);
+			printf("Entire disk: %s %s", label, scapa);
 		else
-			printf("Partition %d: %s %s", npart, label, scap);
+			printf("Partition %d: %s %s", npart, label, scapa);
 
 		if ((linfo.flags & lf_ext_supp) != 0) {
@@ -1037,6 +1037,6 @@
 		printf("\n");
 
-		free(scap);
-		scap = NULL;
+		free(scapa);
+		scapa = NULL;
 		free(sfstype);
 		sfstype = NULL;
@@ -1047,5 +1047,5 @@
 	/* Display available space */
 	if ((linfo.flags & lf_can_create_pri) != 0) {
-		rc = fdisk_part_get_max_avail(dev, spc_pri, &mcap);
+		rc = fdisk_part_get_max_avail(dev, spc_pri, &mcapa);
 		if (rc != EOK) {
 			rc = EIO;
@@ -1053,7 +1053,7 @@
 		}
 
-		cap_simplify(&mcap);
-
-		rc = cap_format(&mcap, &smcap);
+		capa_simplify(&mcapa);
+
+		rc = capa_format(&mcapa, &smcapa);
 		if (rc != EOK) {
 			rc = ENOMEM;
@@ -1062,12 +1062,12 @@
 
 		if ((linfo.flags & lf_ext_supp) != 0)
-			printf("Maximum free primary block: %s\n", smcap);
+			printf("Maximum free primary block: %s\n", smcapa);
 		else
-			printf("Maximum free block: %s\n", smcap);
-
-		free(smcap);
-		smcap = NULL;
-
-		rc = fdisk_part_get_tot_avail(dev, spc_pri, &mcap);
+			printf("Maximum free block: %s\n", smcapa);
+
+		free(smcapa);
+		smcapa = NULL;
+
+		rc = fdisk_part_get_tot_avail(dev, spc_pri, &mcapa);
 		if (rc != EOK) {
 			rc = EIO;
@@ -1075,7 +1075,7 @@
 		}
 
-		cap_simplify(&mcap);
-
-		rc = cap_format(&mcap, &smcap);
+		capa_simplify(&mcapa);
+
+		rc = capa_format(&mcapa, &smcapa);
 		if (rc != EOK) {
 			rc = ENOMEM;
@@ -1084,15 +1084,15 @@
 
 		if ((linfo.flags & lf_ext_supp) != 0)
-			printf("Total free primary space: %s\n", smcap);
+			printf("Total free primary space: %s\n", smcapa);
 		else
-			printf("Total free space: %s\n", smcap);
-
-		free(smcap);
-		smcap = NULL;
+			printf("Total free space: %s\n", smcapa);
+
+		free(smcapa);
+		smcapa = NULL;
 	}
 
 	/* Display available space */
 	if ((linfo.flags & lf_can_create_log) != 0) {
-		rc = fdisk_part_get_max_avail(dev, spc_log, &mcap);
+		rc = fdisk_part_get_max_avail(dev, spc_log, &mcapa);
 		if (rc != EOK) {
 			rc = EIO;
@@ -1100,7 +1100,7 @@
 		}
 
-		cap_simplify(&mcap);
-
-		rc = cap_format(&mcap, &smcap);
+		capa_simplify(&mcapa);
+
+		rc = capa_format(&mcapa, &smcapa);
 		if (rc != EOK) {
 			rc = ENOMEM;
@@ -1108,9 +1108,9 @@
 		}
 
-		printf("Maximum free logical block: %s\n", smcap);
-		free(smcap);
-		smcap = NULL;
-
-		rc = fdisk_part_get_tot_avail(dev, spc_log, &mcap);
+		printf("Maximum free logical block: %s\n", smcapa);
+		free(smcapa);
+		smcapa = NULL;
+
+		rc = fdisk_part_get_tot_avail(dev, spc_log, &mcapa);
 		if (rc != EOK) {
 			rc = EIO;
@@ -1118,7 +1118,7 @@
 		}
 
-		cap_simplify(&mcap);
-
-		rc = cap_format(&mcap, &smcap);
+		capa_simplify(&mcapa);
+
+		rc = capa_format(&mcapa, &smcapa);
 		if (rc != EOK) {
 			rc = ENOMEM;
@@ -1126,7 +1126,7 @@
 		}
 
-		printf("Total free logical space: %s\n", smcap);
-		free(smcap);
-		smcap = NULL;
+		printf("Total free logical space: %s\n", smcapa);
+		free(smcapa);
+		smcapa = NULL;
 	}
 
@@ -1279,7 +1279,7 @@
 	return EOK;
 error:
-	free(sdcap);
-	free(scap);
-	free(smcap);
+	free(sdcapa);
+	free(scapa);
+	free(smcapa);
 	free(sfstype);
 	free(svcname);
Index: uspace/app/sysinst/sysinst.c
===================================================================
--- uspace/app/sysinst/sysinst.c	(revision b3c185b62f0fa507e9d72bce104161ccdb4b3d57)
+++ uspace/app/sysinst/sysinst.c	(revision ecb7828095d2afcbe676486fada5cd94b53906da)
@@ -38,5 +38,5 @@
 #include <block.h>
 #include <byteorder.h>
-#include <cap.h>
+#include <capa.h>
 #include <errno.h>
 #include <fdisk.h>
@@ -98,5 +98,5 @@
 	fdisk_part_spec_t pspec;
 	fdisk_part_info_t pinfo;
-	cap_spec_t cap;
+	capa_spec_t capa;
 	service_id_t sid;
 	errno_t rc;
@@ -137,5 +137,5 @@
 	printf("sysinst_label_dev(): create partition\n");
 
-	rc = fdisk_part_get_max_avail(fdev, spc_pri, &cap);
+	rc = fdisk_part_get_max_avail(fdev, spc_pri, &capa);
 	if (rc != EOK) {
 		printf("Error getting available capacity: %s.\n", str_error(rc));
@@ -144,5 +144,5 @@
 
 	fdisk_pspec_init(&pspec);
-	pspec.capacity = cap;
+	pspec.capacity = capa;
 	pspec.pkind = lpk_primary;
 	pspec.fstype = fs_ext4; /* Cannot be changed without modifying core.img */
Index: uspace/app/trace/syscalls.c
===================================================================
--- uspace/app/trace/syscalls.c	(revision b3c185b62f0fa507e9d72bce104161ccdb4b3d57)
+++ uspace/app/trace/syscalls.c	(revision ecb7828095d2afcbe676486fada5cd94b53906da)
@@ -38,20 +38,40 @@
 
 const sc_desc_t syscall_desc[] = {
+	/* System management syscalls. */
 	[SYS_KIO] = { "kio", 3, V_INT_ERRNO },
 
+	/* Thread and task related syscalls. */
 	[SYS_THREAD_CREATE] = { "thread_create", 3, V_ERRNO },
 	[SYS_THREAD_EXIT] = { "thread_exit", 1, V_ERRNO },
 	[SYS_THREAD_GET_ID] = { "thread_get_id", 1, V_ERRNO },
+	[SYS_THREAD_USLEEP] = { "thread_usleep", 1, V_ERRNO },
+	[SYS_THREAD_UDELAY] = { "thread_udelay", 1, V_ERRNO },
 
 	[SYS_TASK_GET_ID] = { "task_get_id", 1, V_ERRNO },
 	[SYS_TASK_SET_NAME] = { "task_set_name", 2, V_ERRNO },
+	[SYS_TASK_KILL] = { "task_kill", 1, V_ERRNO },
+	[SYS_TASK_EXIT] = { "task_exit", 1, V_ERRNO },
+	[SYS_PROGRAM_SPAWN_LOADER] = { "program_spawn_loader", 2, V_ERRNO },
 
+	/* Synchronization related syscalls. */
+	[SYS_WAITQ_CREATE] = { "waitq_create", 1, V_ERRNO },
+	[SYS_WAITQ_SLEEP] = { "waitq_sleep", 3, V_ERRNO },
+	[SYS_WAITQ_WAKEUP] = { "waitq_wakeup", 1, V_ERRNO },
+	[SYS_WAITQ_DESTROY] = { "waitq_destroy", 1, V_ERRNO },
+	[SYS_SMC_COHERENCE] = { "smc_coherence", 2, V_ERRNO },
+
+	/* Address space related syscalls. */
 	[SYS_AS_AREA_CREATE] = { "as_area_create", 5, V_ERRNO },
 	[SYS_AS_AREA_RESIZE] = { "as_area_resize", 3, V_ERRNO },
+	[SYS_AS_AREA_CHANGE_FLAGS] = { "as_area_change_flags", 2, V_ERRNO },
+	[SYS_AS_AREA_GET_INFO] = { "as_area_get_info", 2, V_ERRNO },
 	[SYS_AS_AREA_DESTROY] = { "as_area_destroy", 1, V_ERRNO },
 
+	/* Page mapping related syscalls. */
+	[SYS_PAGE_FIND_MAPPING] = { "page_find_mapping", 2, V_ERRNO },
+
+	/* IPC related syscalls. */
 	[SYS_IPC_CALL_ASYNC_FAST] = { "ipc_call_async_fast", 6, V_HASH },
 	[SYS_IPC_CALL_ASYNC_SLOW] = { "ipc_call_async_slow", 3, V_HASH },
-
 	[SYS_IPC_ANSWER_FAST] = { "ipc_answer_fast", 6, V_ERRNO },
 	[SYS_IPC_ANSWER_SLOW] = { "ipc_answer_slow", 2, V_ERRNO },
@@ -61,17 +81,29 @@
 	[SYS_IPC_POKE] = { "ipc_poke", 0, V_ERRNO },
 	[SYS_IPC_HANGUP] = { "ipc_hangup", 1, V_ERRNO },
+	[SYS_IPC_CONNECT_KBOX] = { "ipc_connect_kbox", 2, V_ERRNO },
 
+	/* Event notification syscalls. */
 	[SYS_IPC_EVENT_SUBSCRIBE] = { "ipc_event_subscribe", 2, V_ERRNO },
 	[SYS_IPC_EVENT_UNSUBSCRIBE] = { "ipc_event_unsubscribe", 1, V_ERRNO },
 	[SYS_IPC_EVENT_UNMASK] = { "ipc_event_unmask", 1, V_ERRNO },
 
+	/* Permission related syscalls. */
 	[SYS_PERM_GRANT] = { "perm_grant", 2, V_ERRNO },
 	[SYS_PERM_REVOKE] = { "perm_revoke", 2, V_ERRNO },
+
+	/* DDI related syscalls. */
 	[SYS_PHYSMEM_MAP] = { "physmem_map", 4, V_ERRNO },
+	[SYS_PHYSMEM_UNMAP] = { "physmem_unmap", 1, V_ERRNO },
+	[SYS_DMAMEM_MAP] = { "dmamem_map", 6, V_ERRNO },
+	[SYS_DMAMEM_UNMAP] = { "dmamem_unmap", 3, V_ERRNO },
 	[SYS_IOSPACE_ENABLE] = { "iospace_enable", 1, V_ERRNO },
+	[SYS_IOSPACE_DISABLE] = { "iospace_disable", 1, V_ERRNO },
 
 	[SYS_IPC_IRQ_SUBSCRIBE] = { "ipc_irq_subscribe", 4, V_ERRNO },
 	[SYS_IPC_IRQ_UNSUBSCRIBE] = { "ipc_irq_unsubscribe", 2, V_ERRNO },
 
+	/* Sysinfo syscalls. */
+	[SYS_SYSINFO_GET_KEYS_SIZE] = { "sysinfo_get_keys_size", 3, V_ERRNO },
+	[SYS_SYSINFO_GET_KEYS] = { "sysinfo_get_keys", 5, V_ERRNO },
 	[SYS_SYSINFO_GET_VAL_TYPE] = { "sysinfo_get_val_type", 2, V_INTEGER },
 	[SYS_SYSINFO_GET_VALUE] = { "sysinfo_get_value", 3, V_ERRNO },
@@ -79,6 +111,8 @@
 	[SYS_SYSINFO_GET_DATA] = { "sysinfo_get_data", 5, V_ERRNO },
 
+	/* Kernel console syscalls. */
 	[SYS_DEBUG_CONSOLE] = { "debug_console", 0, V_ERRNO },
-	[SYS_IPC_CONNECT_KBOX] = { "ipc_connect_kbox", 1, V_ERRNO }
+
+	[SYS_KLOG] = { "klog", 5, V_ERRNO }
 };
 
Index: uspace/app/trace/trace.c
===================================================================
--- uspace/app/trace/trace.c	(revision b3c185b62f0fa507e9d72bce104161ccdb4b3d57)
+++ uspace/app/trace/trace.c	(revision ecb7828095d2afcbe676486fada5cd94b53906da)
@@ -47,5 +47,4 @@
 #include <mem.h>
 #include <str.h>
-#include <loader/loader.h>
 #include <io/console.h>
 #include <io/keycode.h>
@@ -86,6 +85,9 @@
 void thread_trace_start(uintptr_t thread_hash);
 
+static char *cmd_path;
+static char **cmd_args;
+
 static task_id_t task_id;
-static loader_t *task_ldr;
+static task_wait_t task_w;
 static bool task_wait_for;
 
@@ -93,19 +95,5 @@
 display_mask_t display_mask;
 
-static errno_t program_run_fibril(void *arg);
 static errno_t cev_fibril(void *arg);
-
-static void program_run(void)
-{
-	fid_t fid;
-
-	fid = fibril_create(program_run_fibril, NULL);
-	if (fid == 0) {
-		printf("Error creating fibril\n");
-		exit(1);
-	}
-
-	fibril_add_ready(fid);
-}
 
 static void cev_fibril_start(void)
@@ -122,49 +110,59 @@
 }
 
-static errno_t program_run_fibril(void *arg)
-{
-	errno_t rc;
-
-	/*
-	 * This must be done in background as it will block until
-	 * we let the task reply to this call.
-	 */
-	rc = loader_run(task_ldr);
+static errno_t program_run(void)
+{
+	errno_t rc;
+
+	rc = task_spawnv_debug(&task_id, &task_w, cmd_path,
+	    (const char *const *)cmd_args, &sess);
+
+	if (rc == ENOTSUP) {
+		printf("You do not have userspace debugging support "
+		    "compiled in the kernel.\n");
+		printf("Compile kernel with 'Support for userspace debuggers' "
+		    "(CONFIG_UDEBUG) enabled.\n");
+	}
+
 	if (rc != EOK) {
-		printf("Error running program\n");
-		exit(1);
-	}
-
-	task_ldr = NULL;
-
-	printf("program_run_fibril exiting\n");
-	return 0;
+		printf("Error running program (%s)\n", str_error_name(rc));
+		return rc;
+	}
+
+	return EOK;
 }
 
 static errno_t connect_task(task_id_t task_id)
 {
-	async_sess_t *ksess = async_connect_kbox(task_id);
-
-	if (!ksess) {
-		if (errno == ENOTSUP) {
-			printf("You do not have userspace debugging support "
-			    "compiled in the kernel.\n");
-			printf("Compile kernel with 'Support for userspace debuggers' "
-			    "(CONFIG_UDEBUG) enabled.\n");
-			return errno;
-		}
-
-		printf("Error connecting\n");
-		printf("ipc_connect_task(%" PRIu64 ") -> %s ", task_id, str_error_name(errno));
-		return errno;
-	}
-
-	errno_t rc = udebug_begin(ksess);
-	if (rc != EOK) {
-		printf("udebug_begin() -> %s\n", str_error_name(rc));
-		return rc;
-	}
-
-	rc = udebug_set_evmask(ksess, UDEBUG_EM_ALL);
+	errno_t rc;
+	bool debug_started = false;
+	bool wait_set_up = false;
+
+	if (sess == NULL) {
+		sess = async_connect_kbox(task_id);
+		if (sess == NULL) {
+			printf("Error connecting to task %" PRIu64 ".\n",
+			    task_id);
+			rc = EIO;
+			goto error;
+		}
+
+		rc = udebug_begin(sess);
+		if (rc != EOK) {
+			printf("Error starting debug session.\n");
+			goto error;
+		}
+
+		debug_started = true;
+
+		rc = task_setup_wait(task_id, &task_w);
+		if (rc != EOK) {
+			printf("Error setting up wait for task termination.\n");
+			goto error;
+		}
+
+		wait_set_up = true;
+	}
+
+	rc = udebug_set_evmask(sess, UDEBUG_EM_ALL);
 	if (rc != EOK) {
 		printf("udebug_set_evmask(0x%x) -> %s\n ", UDEBUG_EM_ALL, str_error_name(rc));
@@ -172,6 +170,13 @@
 	}
 
-	sess = ksess;
-	return 0;
+	return EOK;
+error:
+	if (wait_set_up)
+		task_cancel_wait(&task_w);
+	if (debug_started)
+		udebug_end(sess);
+	if (sess != NULL)
+		async_hangup(sess);
+	return rc;
 }
 
@@ -198,5 +203,5 @@
 	printf("\ntotal of %zu threads\n", tb_needed / sizeof(uintptr_t));
 
-	return 0;
+	return EOK;
 }
 
@@ -488,5 +493,5 @@
 
 	printf("Finished tracing thread [%d].\n", thread_id);
-	return 0;
+	return EOK;
 }
 
@@ -502,76 +507,4 @@
 	}
 	fibril_add_ready(fid);
-}
-
-static loader_t *preload_task(const char *path, char **argv,
-    task_id_t *task_id)
-{
-	loader_t *ldr;
-	errno_t rc;
-
-	/* Spawn a program loader */
-	ldr = loader_connect();
-	if (ldr == NULL)
-		return NULL;
-
-	/* Get task ID. */
-	rc = loader_get_task_id(ldr, task_id);
-	if (rc != EOK)
-		goto error;
-
-	/* Send program. */
-	rc = loader_set_program_path(ldr, path);
-	if (rc != EOK)
-		goto error;
-
-	/* Send arguments */
-	rc = loader_set_args(ldr, (const char **) argv);
-	if (rc != EOK)
-		goto error;
-
-	/* Send default files */
-	int fd_root;
-	int fd_stdin;
-	int fd_stdout;
-	int fd_stderr;
-
-	fd_root = vfs_root();
-	if (fd_root >= 0) {
-		rc = loader_add_inbox(ldr, "root", fd_root);
-		vfs_put(fd_root);
-		if (rc != EOK)
-			goto error;
-	}
-
-	if ((stdin != NULL) && (vfs_fhandle(stdin, &fd_stdin) == EOK)) {
-		rc = loader_add_inbox(ldr, "stdin", fd_stdin);
-		if (rc != EOK)
-			goto error;
-	}
-
-	if ((stdout != NULL) && (vfs_fhandle(stdout, &fd_stdout) == EOK)) {
-		rc = loader_add_inbox(ldr, "stdout", fd_stdout);
-		if (rc != EOK)
-			goto error;
-	}
-
-	if ((stderr != NULL) && (vfs_fhandle(stderr, &fd_stderr) == EOK)) {
-		rc = loader_add_inbox(ldr, "stderr", fd_stderr);
-		if (rc != EOK)
-			goto error;
-	}
-
-	/* Load the program. */
-	rc = loader_load_program(ldr);
-	if (rc != EOK)
-		goto error;
-
-	/* Success */
-	return ldr;
-
-	/* Error exit */
-error:
-	loader_abort(ldr);
-	return NULL;
 }
 
@@ -807,5 +740,4 @@
 				++argv;
 				task_id = strtol(*argv, &err_p, 10);
-				task_ldr = NULL;
 				task_wait_for = false;
 				if (*err_p) {
@@ -848,5 +780,6 @@
 		printf("'%s'\n", *cp++);
 
-	task_ldr = preload_task(*argv, argv, &task_id);
+	cmd_path = *argv;
+	cmd_args = argv;
 	task_wait_for = true;
 
@@ -869,4 +802,7 @@
 
 	main_init();
+
+	if (cmd_path != NULL)
+		program_run();
 
 	rc = connect_task(task_id);
@@ -878,7 +814,4 @@
 	printf("Connected to task %" PRIu64 ".\n", task_id);
 
-	if (task_ldr != NULL)
-		program_run();
-
 	cev_fibril_start();
 	trace_task(task_id);
@@ -887,5 +820,5 @@
 		printf("Waiting for task to exit.\n");
 
-		rc = task_wait_task_id(task_id, &texit, &retval);
+		rc = task_wait(&task_w, &texit, &retval);
 		if (rc != EOK) {
 			printf("Failed waiting for task.\n");
