Sort of working, having a pointer error though in the threads somewhere