private void gameLoop() {
		long beginTime, timeTaken, timeLeft; //used to control the timing.
		while(true) {
			beginTime = System.nanoTime();
			if (state == State.GAMEOVER) {
				System.out.println("GAME OVER");
			}
			
			else if (state == State.NEW_GAME) {
				findNewGame();
			}
		
			else if (state == State.WAITING) {
				state = State.INITIALIZE;
			}
			else if(state == State.INITIALIZE) {
				
				gameInit();
				
			}
			else if (state == State.PLAYING) {
				//Check state of game, update score, check if game is finished.
				gameUpdate();
				
				board.repaint();
			}

			
			//Delay timer to provide the necessary delay to meet target rate
			timeTaken = System.nanoTime() - beginTime;
			timeLeft = (UPDATE_PERIOD - timeTaken) / 1000000; //in milliseconds
			if(timeLeft < 10) timeLeft = 10; //set a minimum sleep time
			try {
				Thread.sleep(timeLeft);
			} catch (InterruptedException e) {}
		}
	}