Refactored code, fixed "Couldn't stop all threads" message to be shown in correct circumstances.