added fflush after printfs