Rewrote code
Tested on Mac. Needs testing on Windows.
Couldn't reproduce bug where it would stop responding