Adding thread safety using RLock

Fixing broken unit test