Adress swing threading and cleanup the code