first attempts to making it threadsafe