Index: test/mm/falloc1/test.c
===================================================================
--- test/mm/falloc1/test.c	(revision 1093620503b2f69322a4608d2a3ce6af5b4336cd)
+++ test/mm/falloc1/test.c	(revision df09142fc921be2b6eee959f06e636a75aa46994)
@@ -34,4 +34,5 @@
 #include <arch/types.h>
 #include <debug.h>
+#include <align.h>
 
 #define MAX_FRAMES 1024
@@ -48,13 +49,14 @@
 
 	ASSERT(TEST_RUNS > 1);
+	ASSERT(frames != NULL)
 
-	for (run=0;run<=TEST_RUNS;run++) {
-		for (order=0;order<=MAX_ORDER;order++) {
-			printf("Allocating %d frames blocks ... ", 1<<order);
+	for (run = 0; run < TEST_RUNS; run++) {
+		for (order = 0; order <= MAX_ORDER; order++) {
+			printf("Allocating %d frames blocks ... ", 1 << order);
 			allocated = 0;
-			for (i=0;i<MAX_FRAMES>>order;i++) {
+			for (i = 0; i < MAX_FRAMES >> order; i++) {
 				frames[allocated] = frame_alloc(FRAME_NON_BLOCKING | FRAME_KA, order, &status);
 				
-				if (frames[allocated] % (FRAME_SIZE << order) != 0) {
+				if (ALIGN_UP(frames[allocated], FRAME_SIZE << order) != frames[allocated]) {
 					panic("Test failed. Block at address %X (size %dK) is not aligned\n", frames[allocated], (FRAME_SIZE << order) >> 10);
 				}
@@ -68,5 +70,5 @@
 			}
 		
-			printf("%d blocks alocated.\n", allocated);
+			printf("%d blocks allocated.\n", allocated);
 		
 			if (run) {
@@ -74,8 +76,9 @@
 					panic("Test failed. Frame leak possible.\n");
 				}
-			} else results[order] = allocated;
+			} else
+				results[order] = allocated;
 			
 			printf("Deallocating ... ");
-			for (i=0;i<allocated;i++) {
+			for (i = 0; i < allocated; i++) {
 				frame_free(frames[i]);
 			}
@@ -86,5 +89,5 @@
 	free(frames);
 	
-	printf("Test passed\n");
+	printf("Test passed.\n");
 }
 
Index: test/mm/falloc2/test.c
===================================================================
--- test/mm/falloc2/test.c	(revision 1093620503b2f69322a4608d2a3ce6af5b4336cd)
+++ test/mm/falloc2/test.c	(revision df09142fc921be2b6eee959f06e636a75aa46994)
@@ -37,4 +37,5 @@
 #include <proc/thread.h>
 #include <memstr.h>
+#include <arch.h>
 
 #define MAX_FRAMES 256
@@ -49,21 +50,21 @@
 static atomic_t thread_count;
 
-void thread(void * arg) {
-	int status, order, run, allocated,i;
-	
-	__u8 val = *((__u8 *) arg);
+void thread(void * arg)
+{
+	int status, order, run, allocated, i;
+	__u8 val = THREAD->tid % THREADS;
 	index_t k;
 	
 	__address * frames =  (__address *) malloc(MAX_FRAMES * sizeof(__address));
+	ASSERT(frames != NULL);
 
-	for (run=0;run<THREAD_RUNS;run++) {
-	
-		for (order=0;order<=MAX_ORDER;order++) {
-			printf("Thread #%d: Allocating %d frames blocks ... \n",val, 1<<order);
+	for (run = 0; run < THREAD_RUNS; run++) {
+		for (order = 0; order <= MAX_ORDER; order++) {
+			printf("Thread #%d: Allocating %d frames blocks ... \n", THREAD->tid, 1 << order);
 			allocated = 0;
-			for (i=0;i < (MAX_FRAMES >> order);i++) {
-				frames[allocated] = frame_alloc(FRAME_NON_BLOCKING | FRAME_KA,order, &status);
+			for (i = 0; i < (MAX_FRAMES >> order); i++) {
+				frames[allocated] = frame_alloc(FRAME_NON_BLOCKING | FRAME_KA, order, &status);
 				if (status == 0) {
-					memsetb(frames[allocated], (1 << order) * FRAME_SIZE, val);
+					memsetb(frames[allocated], FRAME_SIZE << order, val);
 					allocated++;
 				} else {
@@ -71,18 +72,14 @@
 				}
 			}
-		
-			printf("Thread #%d: %d blocks alocated.\n",val, allocated);
+			printf("Thread #%d: %d blocks allocated.\n", THREAD->tid, allocated);
 
-			printf("Thread #%d: Deallocating ... \n", val);
-			for (i=0;i<allocated;i++) {
-			
-				for (k=0;k<=((FRAME_SIZE << order) - 1);k++) {
-					if ( ((char *) frames[i])[k] != val ) {
-						printf("Thread #%d: Unexpected data in block %P offset %X\n",val, frames[i], k);
+			printf("Thread #%d: Deallocating ... \n", THREAD->tid);
+			for (i = 0; i < allocated; i++) {
+				for (k = 0; k <= ((FRAME_SIZE << order) - 1); k++) {
+					if (((__u8 *) frames[i])[k] != val) {
+						printf("Thread #%d: Unexpected data (%d) in block %P offset %X\n", THREAD->tid, ((char *) frames[i])[k], frames[i], k);
 						failed();
 					}
-				
 				}
-				
 				frame_free(frames[i]);
 			}
@@ -91,29 +88,34 @@
 	}
 	
+	free(frames);
 	
 	atomic_dec(&thread_count);
-
 }
 
 
-void failed(void) {
+void failed(void)
+{
 	panic("Test failed.\n");
 }
 
 
-void test(void) {
+void test(void)
+{
 	int i;
 
 	atomic_set(&thread_count, THREADS);
 		
-	for (i=1;i<=THREADS;i++) {
+	for (i = 0; i < THREADS; i++) {
 		thread_t * thrd;
-		thrd = thread_create(thread, &i, TASK, 0);
-		if (thrd) thread_ready(thrd); else failed();
+		thrd = thread_create(thread, NULL, TASK, 0);
+		if (thrd)
+			thread_ready(thrd);
+		else
+			failed();
 	}
 	
-	while (thread_count.count);
+	while (thread_count.count)
+		;
 
-	printf("Test passed\n");
+	printf("Test passed.\n");
 }
-
