Fixed incorrect output with sample sizes 2^16 and larger