Check for garbage value on totalBytes and correct (int) casts