added threading and fixed some stuff up