change a mutex to rwlock and work on cleanup