Fixed timing and data-race issues, as well as optimizing