private void storeStats() { 
    frameCount++;
    statsInterval += period;

    if (statsInterval >= MAX_STATS_INTERVAL) {     // record stats every MAX_STATS_INTERVAL
      long timeNow = System.nanoTime() ;
      timeSpentInGame = (int) ((timeNow - gameStartTime)/1000000000L);  // ns --> secs

      long realElapsedTime = timeNow - prevStatsTime;   // time since last stats collection
      totalElapsedTime += realElapsedTime;

      double timingError = 
         ((double)(realElapsedTime - statsInterval) / statsInterval) * 100.0;

      totalFramesSkipped += framesSkipped;

      double actualFPS = 0;     // calculate the latest FPS and UPS
      double actualUPS = 0;
      if (totalElapsedTime > 0) {
        actualFPS = (((double)frameCount / totalElapsedTime) * 1000000000L);
        actualUPS = (((double)(frameCount + totalFramesSkipped) / totalElapsedTime) 
                                                             * 1000000000L);
      }

      // store the latest FPS and UPS
      fpsStore[ (int)statsCount%NUM_FPS ] = actualFPS;
      upsStore[ (int)statsCount%NUM_FPS ] = actualUPS;
      statsCount = statsCount+1;

      double totalFPS = 0.0;     // total the stored FPSs and UPSs
      double totalUPS = 0.0;
      for (int i=0; i < NUM_FPS; i++) {
        totalFPS += fpsStore[i];
        totalUPS += upsStore[i];
      }

      if (statsCount < NUM_FPS) { // obtain the average FPS and UPS
        averageFPS = totalFPS/statsCount;
        averageUPS = totalUPS/statsCount;
      }
      else {
        averageFPS = totalFPS/NUM_FPS;
        averageUPS = totalUPS/NUM_FPS;
      }
      theFrame.setFPS("Your Score: " + theModel.getScore()); //output current score
      //output current power-up
      if (theModel.getPowerUp() != "None" && theModel.getPowerUp() != "HP Up") {
          theFrame.setPWR("Power-Up: " + theModel.getPowerUp() + " (Expires in " + ((theModel.getTime() / 60) + 1) + ")");
      } else {
    	  theFrame.setPWR("Power-Up: " + theModel.getPowerUp());
      }
      
      //output current number of lives
      if (theModel.getNumLives() > 0 && !theModel.checkWin()) {
    	  theFrame.setUPS("Lives Left: " + theModel.getNumLives());	  
      } else if (theModel.checkWin()) {
    	  theFrame.setUPS("A winner is you!");
      } else {
    	  theFrame.setUPS("Game Over");	  
      }

      framesSkipped = 0;
      prevStatsTime = timeNow;
      statsInterval = 0L;   // reset
    }
  }