some tweaks, should be thread safe