fix output for data above 4GB, some checks to avoid pathological behaviour