added main control code