1 foreach + 3 if's is a bit too much...