FIX: Wasn't working when called from a thread other than the main thread.