resolving some hidden thread safety issues