Large overhaul of exception handling and handling/closing of threads to fix threads not closing correctly and other exceptions