Add locks everywhere. Hopefully it will solve thread problems.