Fixed race conditions and added printing of error in mean stats