added scoped_mutex for additional exception safety