threading, race conditions resolved