Also factorized code to make stats. The parallel version does not seem to work due to serialization issues, though.