 {
 	while (!Serial.available());
 
-	delay(25);
+	delay(5);
 
 	while(Serial.available()) 
 	{
-		if (Serial.available() > 0) 
-		{
-			char data = (char)Serial.read();
-			cmd += data;
-
-			if(data == 0x0A) {
-
-				flashColorThread.enabled = false;
-				alternateColorsThread.enabled = false;
-				fadeThread.enabled = false;
-
-				setBrightness(255);
-
-				switch (cmd[0])
-				{
-					case (char)SHOW_COLOR:
-						setColor(-1, cmd[1], cmd[2], cmd[3]);
-						break;
-
-					case (char)SET_BRIGHTNESS:
-						setBrightness(cmd[1]);
-						break;
-
-					case (char)TWO_COLOR:
-						setColor(0, cmd[1], cmd[2], cmd[3]);
-						setColor(1, cmd[4], cmd[5], cmd[6]);
-						break;
-
-					case (char)ALTERNATE_COLORS:
-						colorOne[0] = cmd[1];
-						colorOne[1] = cmd[2];
-						colorOne[2] = cmd[3];
-
-						colorTwo[0] = cmd[4];
-						colorTwo[1] = cmd[5];
-						colorTwo[2] = cmd[6];
-
-						alternateColorsThread.setInterval(cmd[7] * 100);
-						alternateColorsThread.enabled = true;
-						break;
-
-					case (char)FLASH_COLOR:
-						colorOne[0] = cmd[1];
-						colorOne[1] = cmd[2];
-						colorOne[2] = cmd[3];
-
-						flashColorThread.setInterval(cmd[4] * 100);
-						flashColorThread.enabled = true;
-						break;
-
-					case (char)SHOW_RAINBOW:
-						showRainbow(cmd[1]);
-						break;
-
-					case (char)FADE:
-						setColor(-1, cmd[1], cmd[2], cmd[3]);
-						fadeBrightness = 255;
-						isFadingDown = true;
-
-						Serial.println(cmd[4] * 1);
-
-						fadeThread.setInterval(cmd[4] * 1);
-						fadeThread.enabled = true;
-						break;
-				}
+		char data = (char)Serial.read();
+		cmd += data;
+
+		if(data == 0x0A) {
+
+			flashColorThread.enabled = false;
+			alternateColorsThread.enabled = false;
+			fadeThread.enabled = false;
+			rainbowThread.enabled = false;
+				
+			setBrightness(255);
+
+			switch (cmd[0])
+			{
+				case (char)SHOW_COLOR:
+					colorOne[0] = cmd[1];
+					colorOne[1] = cmd[2];
+					colorOne[2] = cmd[3];
+
+					setColor(-1, cmd[1], cmd[2], cmd[3]);
+					break;
+
+				case (char)SET_BRIGHTNESS:
+					setBrightness(cmd[1]);
+					break;
+
+				case (char)TWO_COLOR:
+					setColor(0, cmd[1], cmd[2], cmd[3]);
+					setColor(1, cmd[4], cmd[5], cmd[6]);
+					break;
+
+				case (char)ALTERNATE_COLORS:
+					colorOne[0] = cmd[1];
+					colorOne[1] = cmd[2];
+					colorOne[2] = cmd[3];
+
+					colorTwo[0] = cmd[4];
+					colorTwo[1] = cmd[5];
+					colorTwo[2] = cmd[6];
+
+					alternateColorsThread.setInterval(cmd[7] * 50);
+					alternateColorsThread.enabled = true;
+					break;
+
+				case (char)FLASH_COLOR:
+					flashColorThread.setInterval(cmd[1] * 50);
+					flashColorThread.enabled = true;
+					break;
+
+				case (char)SHOW_RAINBOW:
+					rainbowCounter = 0;
+
+					rainbowThread.setInterval(cmd[1] * 1);
+					rainbowThread.enabled = true;
+					break;
+
+				case (char)FADE:
+					fadeBrightness = 255;
+					isFadingDown = true;
+
+					fadeThread.setInterval(cmd[1] * 1);
+					fadeThread.enabled = true;
+					break;
+			}
 			
-				cmd = "";
-			}
+			cmd = "";
 		}
 	}
 }

	fadeThread.onRun(fade);
	fadeThread.enabled = false;

	controller.add(&flashColorThread);
	controller.add(&alternateColorsThread);
	controller.add(&fadeThread);
	
	delay(2000);
	Serial.begin(9600);

	pixels.begin();
	pixels.show();
	
	Timer1.initialize(10000);
	Timer1.attachInterrupt(timerCallback);
	Timer1.start();
}
