Updated to dynamically allocate mutexes and support being de-initialized