Scope and thread safety (bugfixes)