Fixed data race on stats, version and refactored the code.