added some more thread safety:)