Remove race conditions and do major bugfixes.