Adds rooted references to scopes in lib.c
Removes rooted references where appropriate