diff --git a/bin/tetris/Main.class b/bin/tetris/Main.class
index 22431629137517532bc159ad0710e953268a672a..09df4da480e4d5572d5c9d24249566b3991be639 100644
Binary files a/bin/tetris/Main.class and b/bin/tetris/Main.class differ
diff --git a/bin/tetris/Ohjain.class b/bin/tetris/Ohjain.class
index 7f85bcf0c6b24470ff52e84312e18fbb75d62a69..6c14b2d7c189e86478d0deccd801c3e3f3446068 100644
Binary files a/bin/tetris/Ohjain.class and b/bin/tetris/Ohjain.class differ
diff --git a/src/tetris/Main.java b/src/tetris/Main.java
index 8e846cf6931d9d9e30ca752cde1a87244ec3428c..fb069b1c7b343c11cfc381edaf6a7d2d8772a53a 100644
--- a/src/tetris/Main.java
+++ b/src/tetris/Main.java
@@ -106,14 +106,16 @@ public class Main extends Application {
 						}
 						 
 						if (!peliOhi) {
-							if (muoto.suurinY() >= KORKEUS - KOKO) {
+							int y = muoto.suurinY();
+							Ohjain.liikutaAlas(muoto);
+							if (muoto.suurinY() == y) {
 								Muoto a = seuraavaMuoto;
 								ikkuna.getChildren().addAll(a.a, a.b, a.c, a.d);
 								moveOnKeyPress(a);
 								muoto = a;
 								seuraavaMuoto = Ohjain.teeMuoto();
+								removeRows(ikkuna);
 							}
-							Ohjain.liikutaAlas(muoto);
 							scoreTeksti.setText("Score: " + Integer.toString(score));
 							taso.setText("Taso: " + Integer.toString(riveja));
 						}
@@ -151,22 +153,122 @@ public class Main extends Application {
 		});
 	}
 	
+	public void nelioAlas(Rectangle nelio) {
+		RUUDUKKO[(int)nelio.getX()/KOKO][(int)nelio.getY()/KOKO] = 0;
+		nelio.setY(nelio.getY()+KOKO);
+		RUUDUKKO[(int)nelio.getX()/KOKO][(int)nelio.getY()/KOKO] = 1;
+	}
+	
 	private void removeRows(Pane pane) {
 		ArrayList<Node> neliot = new ArrayList<>();
-		int rivit = 0;
-		for (int i = 0; i < KORKEUS / KOKO; i++) {
-			int maara = 0;
-			for (int j = 0; j < LEVEYS / KOKO; j++) {
+		ArrayList<Integer> rivit = new ArrayList<>();
+		ArrayList<Rectangle> uudetNeliot = new ArrayList<>();
+		int tayna = 0;
+		int ylinrivi = 100;
+		for (int i = 0; i < RUUDUKKO[0].length; i++) {
+			for (int j = 0; j < RUUDUKKO.length; j++) {	
 				if (RUUDUKKO[j][i] != 0) {
-					maara++;
+					tayna++;					
+				}
+			}
+			if (tayna == RUUDUKKO.length) {
+				rivit.add(i);
+				if (i < ylinrivi) {
+					ylinrivi = i;
+				}
+			}
+			tayna = 0;
+		}
+		
+		for (Node nelio : pane.getChildren()) {
+			if (nelio instanceof Rectangle) {
+				neliot.add(nelio);
+			}
+		}
+		
+		while (true) {
+			ArrayList<Node> poistettavat = new ArrayList<>();
+			boolean lopeta = true;
+			for (Node nelio : neliot) {
+				Rectangle a = (Rectangle) nelio;
+				if (rivit.contains((int)a.getY()/KOKO)) {
+					lopeta = false;
+					pane.getChildren().remove(nelio);
+					poistettavat.add(nelio);
+					RUUDUKKO[(int)a.getX()/KOKO][(int)a.getY()/KOKO] = 0;
+				} else {
+					uudetNeliot.add(a);
 				}
 			}
-			if (maara == LEVEYS / KOKO) {
-				rivit++;
-				riveja++;
+			for (Node pois : poistettavat) {
+				neliot.remove(pois);
+			}
+			
+			
+			
+			if (lopeta) {
+				break;
+			}
+		}
+		
+		for (Rectangle a : uudetNeliot) {
+			for (int j = 0; j < rivit.size(); j++) {
+				if (a.getY()/KOKO < ylinrivi) {
+					for (int r : rivit) {
+						nelioAlas(a);
 				
+					}
+				}
 			}
 		}
+		
+			
+//		if (rivit.size() > 0) {
+//			do {
+//				for (Node nelio : pane.getChildren()) {
+//					if (nelio instanceof Rectangle) {
+//						neliot.add(nelio);
+//					}
+//				}
+//				score += 50;
+//				riveja++;
+//			
+//				for (Node nelio : neliot) {
+//					Rectangle a =  (Rectangle) nelio;
+//					if (a.getY() == rivit.get(0)*KOKO) {
+//						RUUDUKKO[(int) a.getX()/KOKO][(int) a.getY()/KOKO] = 0;
+//						pane.getChildren().remove(nelio);
+//					} else {
+//						uudetNeliot.add(nelio);
+//					}
+//				}
+//				for (Node nelio : uudetNeliot) {
+//					Rectangle a = (Rectangle) nelio;
+//					if (a.getY() < rivit.get(0)*KOKO) {
+//						RUUDUKKO[(int)a.getX()/KOKO][(int) a.getY()/KOKO] = 0;
+//						a.setY(a.getY()+KOKO);
+//					}
+//					rivit.remove(0);
+//					neliot.clear();
+//					uudetNeliot.clear();
+//					
+//					for (Node nelio1 : pane.getChildren()) {
+//						if (nelio1 instanceof Rectangle) {
+//							neliot.add(nelio1);
+//						}
+//					}
+//					for (Node nelio2 : neliot) {
+//						Rectangle b = (Rectangle) nelio2;
+//						try {
+//							RUUDUKKO[(int) b.getX()/KOKO][(int) b.getY()/KOKO] = 1;
+//						} catch (ArrayIndexOutOfBoundsException e) {
+//							
+//						}
+//					}
+//					neliot.clear();
+//				}
+//			} while(rivit.size() > 0);
+//		}
 	}
 
 	
diff --git a/src/tetris/Ohjain.java b/src/tetris/Ohjain.java
index be70fd15dd4d56bd322c1fd69a7d16085b09634b..186b9888d8255b4961eb41b229bdacfcf54ea96c 100644
--- a/src/tetris/Ohjain.java
+++ b/src/tetris/Ohjain.java
@@ -12,6 +12,7 @@ public class Ohjain {
 	public static int [][] RUUDUKKO = Main.RUUDUKKO;
 	
 	public static void liikuOikealle(Muoto muoto) {
+		asetaRuudukonArvo(muoto, 0);
 		if (muoto.suurinX() < LEVEYS - KOKO) {
 
 			if (tilaa(muoto, 1, 0)) {
@@ -21,9 +22,11 @@ public class Ohjain {
 				muoto.d.setX(muoto.d.getX() + ASKEL);
 			}
 		}
+		asetaRuudukonArvo(muoto, 1);
 	}
 	
 	public static void liikuVasemmalle(Muoto muoto) {
+		asetaRuudukonArvo(muoto, 0);
 		if (muoto.pieninX() > 0) {
 			int liikutaA = RUUDUKKO[((int) muoto.a.getX() / KOKO) - 1][(int) muoto.a.getY()/KOKO];
 			int liikutaB = RUUDUKKO[((int) muoto.b.getX() / KOKO) - 1][(int) muoto.b.getY()/KOKO];
@@ -37,10 +40,11 @@ public class Ohjain {
 				muoto.d.setX(muoto.d.getX() - ASKEL);
 			}
 		}
+		asetaRuudukonArvo(muoto, 1);
 	}
 	
 	public static void kaanna(Muoto muoto) {
-		
+		asetaRuudukonArvo(muoto, 0);
 		switch (muoto.getNimi()) {
 			case "o":
 				break;
@@ -48,15 +52,26 @@ public class Ohjain {
 				muoto.muutaAsentoa();
 				break;
 		}
+		asetaRuudukonArvo(muoto, 1);
+	}
+	
+	public static void asetaRuudukonArvo(Muoto muoto, int arvo) {
+		RUUDUKKO[(int)muoto.a.getX()/KOKO][(int)muoto.a.getY()/KOKO] = arvo;
+		RUUDUKKO[(int)muoto.b.getX()/KOKO][(int)muoto.b.getY()/KOKO] = arvo;
+		RUUDUKKO[(int)muoto.c.getX()/KOKO][(int)muoto.c.getY()/KOKO] = arvo;
+		RUUDUKKO[(int)muoto.d.getX()/KOKO][(int)muoto.d.getY()/KOKO] = arvo;
 	}
 	
 	public static void liikutaAlas(Muoto muoto) {
-		if (tilaa(muoto, 0, 1)) { //muoto.suurinY() < KORKEUS - KOKO
+		asetaRuudukonArvo(muoto, 0);
+		
+		if (tilaa(muoto, 0, 1)) {
 			muoto.a.setY(muoto.a.getY() + KOKO);
 			muoto.b.setY(muoto.b.getY() + KOKO);
 			muoto.c.setY(muoto.c.getY() + KOKO);
 			muoto.d.setY(muoto.d.getY() + KOKO);
 		}
+		asetaRuudukonArvo(muoto, 1);
 	}
 	
 	public static boolean tilaa(Muoto muoto, int xDiff, int yDiff) {