added fflush() in main loop to get regular updates