writing skeleton of main control loop. See comments, please!