Now a bit more thread safe