added some thread safty ... much more still needed