Index: kernel/generic/include/kobject/kobject.h
===================================================================
--- kernel/generic/include/kobject/kobject.h	(revision 49115ac4234c04a6a0e05c81930353801ea20899)
+++ kernel/generic/include/kobject/kobject.h	(revision e7ac23d02750f85979a275420d969126143b3738)
@@ -42,4 +42,12 @@
 #define MAX_KERNEL_OBJECTS  64
 
+#define for_each_kobject(task, ko, type) \
+	for (int i = 0, l = 1; i < MAX_KERNEL_OBJECTS && l; i++) \
+		for (kobject_t *(ko) = kobject_get((task), i, (type)); \
+		    (ko) && !(l = 0); (ko) = NULL, l = 1)
+
+#define for_each_kobject_current(ko, type) \
+	for_each_kobject(TASK, (ko), (type))
+
 typedef enum {
 	KOBJECT_TYPE_INVALID,
@@ -61,4 +69,8 @@
 struct task;
 
+void kobject_task_alloc(struct task *);
+void kobject_task_free(struct task *);
+void kobject_task_init(struct task *);
+
 extern void kobject_initialize(kobject_t *);
 extern kobject_t *kobject_get(struct task *, int, kobject_type_t);
@@ -67,4 +79,6 @@
 extern void kobject_free(struct task *, int);
 
+extern int kobject_to_cap(struct task *, kobject_t *);
+
 #endif
 
Index: kernel/generic/src/ipc/ipc.c
===================================================================
--- kernel/generic/src/ipc/ipc.c	(revision 49115ac4234c04a6a0e05c81930353801ea20899)
+++ kernel/generic/src/ipc/ipc.c	(revision e7ac23d02750f85979a275420d969126143b3738)
@@ -735,5 +735,5 @@
 {
 	call_t *call;
-	size_t i;
+	bool all_clean;
 
 restart:
@@ -742,8 +742,7 @@
 	 * Locking is needed as there may be connection handshakes in progress.
 	 */
-	for (i = 0; i < MAX_KERNEL_OBJECTS; i++) {
-		phone_t *phone = phone_get_current(i);
-		if (!phone)
-			continue;
+	all_clean = true;
+	for_each_kobject_current(kobj, KOBJECT_TYPE_PHONE) {
+		phone_t *phone = &kobj->phone;
 
 		mutex_lock(&phone->lock);
@@ -781,4 +780,5 @@
 		if (phone->state != IPC_PHONE_FREE) {
 			mutex_unlock(&phone->lock);
+			all_clean = false;
 			break;
 		}
@@ -788,5 +788,5 @@
 		
 	/* Got into cleanup */
-	if (i == MAX_KERNEL_OBJECTS)
+	if (all_clean)
 		return;
 		
@@ -820,8 +820,6 @@
 
 	/* Disconnect all our phones ('ipc_phone_hangup') */
-	for (int i = 0; i < MAX_KERNEL_OBJECTS; i++) {
-		phone_t *phone = phone_get_current(i);
-		if (!phone)
-			continue;
+	for_each_kobject_current(kobj, KOBJECT_TYPE_PHONE) {
+		phone_t *phone = &kobj->phone;
 		ipc_phone_hangup(phone);
 	}
@@ -913,17 +911,15 @@
 	printf("[phone cap] [calls] [state\n");
 	
-	size_t i;
-	for (i = 0; i < MAX_KERNEL_OBJECTS; i++) {
-		phone_t *phone = phone_get(task, i);
-		if (!phone)
+	for_each_kobject(task, kobj, KOBJECT_TYPE_PHONE) {
+		phone_t *phone = &kobj->phone;
+		int cap = kobject_to_cap(task, kobj);
+
+		if (SYNCH_FAILED(mutex_trylock(&phone->lock))) {
+			printf("%-11d (mutex busy)\n", cap);
 			continue;
-
-		if (SYNCH_FAILED(mutex_trylock(&phone->lock))) {
-			printf("%-10zu (mutex busy)\n", i);
-			continue;
 		}
 		
 		if (phone->state != IPC_PHONE_FREE) {
-			printf("%-11zu %7" PRIun " ", i,
+			printf("%-11d %7" PRIun " ", cap,
 			    atomic_get(&phone->active_calls));
 			
Index: kernel/generic/src/kobject/kobject.c
===================================================================
--- kernel/generic/src/kobject/kobject.c	(revision 49115ac4234c04a6a0e05c81930353801ea20899)
+++ kernel/generic/src/kobject/kobject.c	(revision e7ac23d02750f85979a275420d969126143b3738)
@@ -37,4 +37,5 @@
 #include <synch/spinlock.h>
 #include <abi/errno.h>
+#include <mm/slab.h>
 
 void kobject_initialize(kobject_t *kobj)
@@ -42,4 +43,20 @@
 	kobj->type = KOBJECT_TYPE_INVALID;
 	kobj->can_reclaim = NULL;
+}
+
+void kobject_task_alloc(task_t *task)
+{
+	task->kobject = malloc(sizeof(kobject_t) * MAX_KERNEL_OBJECTS, 0);
+}
+
+void kobject_task_init(task_t *task)
+{
+	for (int cap = 0; cap < MAX_KERNEL_OBJECTS; cap++)
+		kobject_initialize(&task->kobject[cap]);
+}
+
+void kobject_task_free(task_t *task)
+{
+	free(task->kobject);
 }
 
@@ -91,4 +108,9 @@
 }
 
+int kobject_to_cap(task_t *task, kobject_t *kobj)
+{
+	return kobj - task->kobject;
+}
+
 /** @}
  */
Index: kernel/generic/src/proc/task.c
===================================================================
--- kernel/generic/src/proc/task.c	(revision 49115ac4234c04a6a0e05c81930353801ea20899)
+++ kernel/generic/src/proc/task.c	(revision e7ac23d02750f85979a275420d969126143b3738)
@@ -168,6 +168,6 @@
 	
 	list_initialize(&task->threads);
-
-	task->kobject = malloc(sizeof(kobject_t) * MAX_KERNEL_OBJECTS, 0);
+	
+	kobject_task_alloc(task);
 	
 	ipc_answerbox_init(&task->answerbox, task);
@@ -190,5 +190,5 @@
 	task_t *task = (task_t *) obj;
 	
-	free(task->kobject);
+	kobject_task_free(task);
 	return 0;
 }
@@ -215,7 +215,5 @@
 	task->kcycles = 0;
 
-	int cap;
-	for (cap = 0; cap < MAX_KERNEL_OBJECTS; cap++)
-		kobject_initialize(&task->kobject[cap]);
+	kobject_task_init(task);
 
 	task->ipc_info.call_sent = 0;
@@ -626,9 +624,9 @@
 	
 	if (*additional) {
-		int i;
-		for (i = 0; i < MAX_KERNEL_OBJECTS; i++) {
-			phone_t *phone = phone_get(task, i);
-			if (phone && phone->callee)
-				printf(" %d:%p", i, phone->callee);
+		for_each_kobject(task, ko, KOBJECT_TYPE_PHONE) {
+			phone_t *phone = &ko->phone;
+			if (phone->callee)
+				printf(" %d:%p", kobject_to_cap(task, ko),
+				    phone->callee);
 		}
 		printf("\n");
