thread and bug fixes