fixing some threading problems