added multithreading to fix the “blocking” the flash was causing