bytesRead moved to where the variable is actually used