Make the implementation more thread safe

Closes rhbz#1012545
Merge pull request #18 from jfilak/rhbz1012545

Make the implementation more thread safe