Fixed threading, but now have a slight buffer overflow issue somewhere