added main loop