Added multithreading and fixed bug not using a new key