Fix and improve part 2

Nevermind the previous commit, I was tired and I had no idea what I'm
doing - and it broke threading...