refactored thread calls to make them threadsafe
added a Ui class