Index: src/libcfa/Makefile.am
===================================================================
--- src/libcfa/Makefile.am	(revision 7453a6885554a2ffbb472a01d68f820f660acf84)
+++ src/libcfa/Makefile.am	(revision 6ff4507486f9107e3974f91b56013917560dfa9d)
@@ -36,5 +36,5 @@
 	 ${AM_V_GEN}@BACKEND_CC@ @CFA_FLAGS@ -D__CFA_DEBUG__ -O0 -c -o $@ $<
 
-EXTRA_FLAGS = -g -Wall -Werror -Wno-unused-function -imacros libcfa-prelude.c @CFA_FLAGS@
+EXTRA_FLAGS = -g -Wall -Wno-unused-function -imacros libcfa-prelude.c @CFA_FLAGS@
 
 AM_CCASFLAGS = @CFA_FLAGS@
Index: src/libcfa/Makefile.in
===================================================================
--- src/libcfa/Makefile.in	(revision 7453a6885554a2ffbb472a01d68f820f660acf84)
+++ src/libcfa/Makefile.in	(revision 6ff4507486f9107e3974f91b56013917560dfa9d)
@@ -416,5 +416,5 @@
 ARFLAGS = cr
 lib_LIBRARIES = $(am__append_1) $(am__append_2)
-EXTRA_FLAGS = -g -Wall -Werror -Wno-unused-function -imacros libcfa-prelude.c @CFA_FLAGS@
+EXTRA_FLAGS = -g -Wall -Wno-unused-function -imacros libcfa-prelude.c @CFA_FLAGS@
 AM_CCASFLAGS = @CFA_FLAGS@
 headers = fstream iostream iterator limits rational stdlib \
Index: src/libcfa/concurrency/monitor.c
===================================================================
--- src/libcfa/concurrency/monitor.c	(revision 7453a6885554a2ffbb472a01d68f820f660acf84)
+++ src/libcfa/concurrency/monitor.c	(revision 6ff4507486f9107e3974f91b56013917560dfa9d)
@@ -24,4 +24,7 @@
 // Forward declarations
 static inline void set_owner( monitor_desc * this, thread_desc * owner );
+static inline void set_owner( monitor_desc ** storage, short count, thread_desc * owner );
+static inline void set_mask ( monitor_desc ** storage, short count, const __waitfor_mask_t & mask );
+
 static inline thread_desc * next_thread( monitor_desc * this );
 static inline bool is_accepted( monitor_desc * this, const __monitor_group_t & monitors );
@@ -32,37 +35,46 @@
 static inline void unlock_all( monitor_desc ** locks, unsigned short count );
 
-static inline void save_recursion   ( monitor_desc ** ctx, unsigned int * /*out*/ recursions, unsigned short count );
-static inline void restore_recursion( monitor_desc ** ctx, unsigned int * /*in */ recursions, unsigned short count );
+static inline void save   ( monitor_desc ** ctx, short count, spinlock ** locks, unsigned int * /*out*/ recursions, __waitfor_mask_t * /*out*/ masks );
+static inline void restore( monitor_desc ** ctx, short count, spinlock ** locks, unsigned int * /*in */ recursions, __waitfor_mask_t * /*in */ masks );
 
 static inline void init     ( int count, monitor_desc ** monitors, __condition_node_t * waiter, __condition_criterion_t * criteria );
 static inline void init_push( int count, monitor_desc ** monitors, __condition_node_t * waiter, __condition_criterion_t * criteria );
 
-static inline thread_desc * check_condition( __condition_criterion_t * );
-static inline void brand_condition( condition * );
-static inline unsigned short insert_unique( thread_desc ** thrds, unsigned short end, thread_desc * val );
-
+static inline thread_desc *        check_condition   ( __condition_criterion_t * );
+static inline void                 brand_condition   ( condition * );
 static inline [thread_desc *, int] search_entry_queue( const __waitfor_mask_t &, monitor_desc ** monitors, int count );
 
-static inline short count_max( const __waitfor_mask_t & mask );
-static inline short aggregate( monitor_desc ** storage, const __waitfor_mask_t & mask );
-static inline void  set_mask ( monitor_desc ** storage, short count, const __waitfor_mask_t & mask );
+forall(dtype T | sized( T ))
+static inline short insert_unique( T ** array, short & size, T * val );
+static inline short count_max    ( const __waitfor_mask_t & mask );
+static inline short aggregate    ( monitor_desc ** storage, const __waitfor_mask_t & mask );
 
 //-----------------------------------------------------------------------------
 // Useful defines
-#define wait_ctx(thrd, user_info)                               /* Create the necessary information to use the signaller stack       */ \
-	__condition_node_t waiter = { thrd, count, user_info };   /* Create the node specific to this wait operation                   */ \
-	__condition_criterion_t criteria[count];                  /* Create the creteria this wait operation needs to wake up          */ \
-	init( count, monitors, &waiter, criteria );               /* Link everything together                                          */ \
-
-#define wait_ctx_primed(thrd, user_info)                        /* Create the necessary information to use the signaller stack       */ \
-	__condition_node_t waiter = { thrd, count, user_info };   /* Create the node specific to this wait operation                   */ \
-	__condition_criterion_t criteria[count];                  /* Create the creteria this wait operation needs to wake up          */ \
-	init_push( count, monitors, &waiter, criteria );          /* Link everything together and push it to the AS-Stack              */ \
-
-#define monitor_ctx( mons, cnt )              /* Define that create the necessary struct for internal/external scheduling operations */ \
-	monitor_desc ** monitors = mons;        /* Save the targeted monitors                                                          */ \
-	unsigned short count = cnt;             /* Save the count to a local variable                                                  */ \
-	unsigned int recursions[ count ];       /* Save the current recursion levels to restore them later                             */ \
-	spinlock *   locks     [ count ];       /* We need to pass-in an array of locks to BlockInternal                               */ \
+#define wait_ctx(thrd, user_info)                               /* Create the necessary information to use the signaller stack                         */ \
+	__condition_node_t waiter = { thrd, count, user_info };   /* Create the node specific to this wait operation                                     */ \
+	__condition_criterion_t criteria[count];                  /* Create the creteria this wait operation needs to wake up                            */ \
+	init( count, monitors, &waiter, criteria );               /* Link everything together                                                            */ \
+
+#define wait_ctx_primed(thrd, user_info)                        /* Create the necessary information to use the signaller stack                         */ \
+	__condition_node_t waiter = { thrd, count, user_info };   /* Create the node specific to this wait operation                                     */ \
+	__condition_criterion_t criteria[count];                  /* Create the creteria this wait operation needs to wake up                            */ \
+	init_push( count, monitors, &waiter, criteria );          /* Link everything together and push it to the AS-Stack                                */ \
+
+#define monitor_ctx( mons, cnt )                                /* Define that create the necessary struct for internal/external scheduling operations */ \
+	monitor_desc ** monitors = mons;                          /* Save the targeted monitors                                                          */ \
+	unsigned short count = cnt;                               /* Save the count to a local variable                                                  */ \
+	unsigned int recursions[ count ];                         /* Save the current recursion levels to restore them later                             */ \
+	__waitfor_mask_t masks[ count ];                          /* Save the current waitfor masks to restore them later                                */ \
+	spinlock *   locks     [ count ];                         /* We need to pass-in an array of locks to BlockInternal                               */ \
+
+#define monitor_save    save   ( monitors, count, locks, recursions, masks )
+#define monitor_restore restore( monitors, count, locks, recursions, masks )
+
+#define blockAndWake( thrd, cnt )                               /* Create the necessary information to use the signaller stack                         */ \
+	monitor_save;                                             /* Save monitor states                                                                 */ \
+	BlockInternal( locks, count, thrd, cnt );                 /* Everything is ready to go to sleep                                                  */ \
+	monitor_restore;                                          /* We are back, restore the owners and recursions                                      */ \
+
 
 //-----------------------------------------------------------------------------
@@ -277,9 +289,9 @@
 	append( &this->blocked, &waiter );
 
-	// Lock all monitors (aggregates the lock them as well)
+	// Lock all monitors (aggregates the locks as well)
 	lock_all( monitors, locks, count );
 
 	// Find the next thread(s) to run
-	unsigned short thread_count = 0;
+	short thread_count = 0;
 	thread_desc * threads[ count ];
 	for(int i = 0; i < count; i++) {
@@ -290,21 +302,8 @@
 	for( int i = 0; i < count; i++) {
 		thread_desc * new_owner = next_thread( monitors[i] );
-		thread_count = insert_unique( threads, thread_count, new_owner );
-	}
-
-	// Save monitor state
-	save_recursion( monitors, recursions, count );
-
-	// Everything is ready to go to sleep
-	BlockInternal( locks, count, threads, thread_count );
-
-
-	// WE WOKE UP
-
-
-	// We are back, restore the owners and recursions
-	lock_all( locks, count );
-	restore_recursion( monitors, recursions, count );
-	unlock_all( locks, count );
+		insert_unique( threads, thread_count, new_owner );
+	}
+
+	blockAndWake( threads, thread_count );
 }
 
@@ -368,11 +367,9 @@
 
 	//save contexts
-	save_recursion( monitors, recursions, count );
+	monitor_save;
 
 	//Find the thread to run
 	thread_desc * signallee = pop_head( &this->blocked )->waiting_thread;
-	for(int i = 0; i < count; i++) {
-		set_owner( monitors[i], signallee );
-	}
+	set_owner( monitors, count, signallee );
 
 	//Everything is ready to go to sleep
@@ -383,8 +380,6 @@
 
 
-	//We are back, restore the owners and recursions
-	lock_all( locks, count );
-	restore_recursion( monitors, recursions, count );
-	unlock_all( locks, count );
+	//We are back, restore the masks and recursions
+	monitor_restore;
 
 	return true;
@@ -424,5 +419,5 @@
 	monitor_ctx( mon_storage, actual_count );
 
-	// Lock all monitors (aggregates the lock them as well)
+	// Lock all monitors (aggregates the locks as well)
 	lock_all( monitors, locks, count );
 
@@ -437,17 +432,5 @@
 			}
 			else {
-				save_recursion( monitors, recursions, count );
-
-				// Everything is ready to go to sleep
-				BlockInternal( locks, count, &next, 1 );
-
-
-				//WE WOKE UP
-
-
-				//We are back, restore the owners and recursions
-				lock_all( locks, count );
-				restore_recursion( monitors, recursions, count );
-				unlock_all( locks, count );
+				blockAndWake( &next, 1 );
 			}
 
@@ -463,21 +446,10 @@
 
 
-	save_recursion( monitors, recursions, count );
+	monitor_save;
 	set_mask( monitors, count, mask );
 
-
-	// Everything is ready to go to sleep
-	BlockInternal( locks, count );
-
-
+	BlockInternal( locks, count );       // Everything is ready to go to sleep
 	//WE WOKE UP
-
-
-	//We are back, restore the owners and recursions
-	lock_all( locks, count );
-	restore_recursion( monitors, recursions, count );
-	unlock_all( locks, count );
-
-	return mask.accepted;
+	monitor_restore;                     //We are back, restore the masks and recursions
 }
 
@@ -491,4 +463,16 @@
 	//We are passing the monitor to someone else, which means recursion level is not 0
 	this->recursion = owner ? 1 : 0;
+}
+
+static inline void set_owner( monitor_desc ** monitors, short count, thread_desc * owner ) {
+	for( int i = 0; i < count; i++ ) {
+		set_owner( monitors[i], owner );
+	}
+}
+
+static inline void set_mask( monitor_desc ** storage, short count, const __waitfor_mask_t & mask ) {
+	for(int i = 0; i < count; i++) {
+		storage[i]->mask = mask;
+	}
 }
 
@@ -513,4 +497,26 @@
 }
 
+static inline bool is_accepted( monitor_desc * this, const __monitor_group_t & group ) {
+	__acceptable_t * it = this->mask.clauses; // Optim
+	int count = this->mask.size;
+
+	// Check if there are any acceptable functions
+	if( !it ) return -1;
+
+	// If this isn't the first monitor to test this, there is no reason to repeat the test.
+	if( this != group[0] ) return group[0]->mask.accepted >= 0;
+
+	// For all acceptable functions check if this is the current function.
+	for( short i = 0; i < count; i++, it++ ) {
+		if( *it == group ) {
+			*this->mask.accepted = i;
+			return true;
+		}
+	}
+
+	// No function matched
+	return false;
+}
+
 static inline void init( int count, monitor_desc ** monitors, __condition_node_t * waiter, __condition_criterion_t * criteria ) {
 	for(int i = 0; i < count; i++) {
@@ -556,15 +562,18 @@
 }
 
-
-static inline void save_recursion   ( monitor_desc ** ctx, unsigned int * /*out*/ recursions, unsigned short count ) {
+static inline void save   ( monitor_desc ** ctx, short count, __attribute((unused)) spinlock ** locks, unsigned int * /*out*/ recursions, __waitfor_mask_t * /*out*/ masks ) {
 	for( int i = 0; i < count; i++ ) {
 		recursions[i] = ctx[i]->recursion;
-	}
-}
-
-static inline void restore_recursion( monitor_desc ** ctx, unsigned int * /*in */ recursions, unsigned short count ) {
+		masks[i]      = ctx[i]->mask;
+	}
+}
+
+static inline void restore( monitor_desc ** ctx, short count, spinlock ** locks, unsigned int * /*out*/ recursions, __waitfor_mask_t * /*out*/ masks ) {
+	lock_all( locks, count );
 	for( int i = 0; i < count; i++ ) {
 		ctx[i]->recursion = recursions[i];
-	}
+		ctx[i]->mask      = masks[i];
+	}
+	unlock_all( locks, count );
 }
 
@@ -607,37 +616,4 @@
 		}
 	}
-}
-
-static inline unsigned short insert_unique( thread_desc ** thrds, unsigned short end, thread_desc * val ) {
-	if( !val ) return end;
-
-	for(int i = 0; i <= end; i++) {
-		if( thrds[i] == val ) return end;
-	}
-
-	thrds[end] = val;
-	return end + 1;
-}
-
-static inline bool is_accepted( monitor_desc * this, const __monitor_group_t & group ) {
-	__acceptable_t * it = this->mask.clauses; // Optim
-	int count = this->mask.size;
-
-	// Check if there are any acceptable functions
-	if( !it ) return -1;
-
-	// If this isn't the first monitor to test this, there is no reason to repeat the test.
-	if( this != group[0] ) return group[0]->mask.accepted >= 0;
-
-	// For all acceptable functions check if this is the current function.
-	for( short i = 0; i < count; i++, it++ ) {
-		if( *it == group ) {
-			*this->mask.accepted = i;
-			return true;
-		}
-	}
-
-	// No function matched
-	return false;
 }
 
@@ -668,4 +644,17 @@
 }
 
+forall(dtype T | sized( T ))
+static inline short insert_unique( T ** array, short & size, T * val ) {
+	if( !val ) return size;
+
+	for(int i = 0; i <= size; i++) {
+		if( array[i] == val ) return size;
+	}
+
+	array[size] = val;
+	size = size + 1;
+	return size;
+}
+
 static inline short count_max( const __waitfor_mask_t & mask ) {
 	short max = 0;
@@ -677,14 +666,13 @@
 
 static inline short aggregate( monitor_desc ** storage, const __waitfor_mask_t & mask ) {
-	#warning function not implemented
-	return 0;
-}
-
-static inline void set_mask( monitor_desc ** storage, short count, const __waitfor_mask_t & mask ) {
-	for(int i = 0; i < count; i++) {
-		storage[i]->mask = mask;
-	}
-}
-
+	short size = 0;
+	for( int i = 0; i < mask.size; i++ ) {
+		for( int j = 0; j < mask.clauses[i].size; j++) {
+			insert_unique( storage, size, mask.clauses[i].list[j] );
+		}
+	}
+	qsort( storage, size );
+	return size;
+}
 
 void ?{}( __condition_blocked_queue_t & this ) {
