This code just looks racy. I understand that goraft is single threaded but is there a better way that doesn't look like a race?