fix for #1, do while to read enough data