Make the implementation more thread safe

Closes rhbz#1012545