Fixes multi thread bug