I'm not sure how important it is but I don't think this is totally thread safe. It might be easier to just synchronize wherever handlers are used