Added smart mutex lock and unload functions