Added missing files and reworked the threading.