Fixed several thread and UI bugs