Refactored scope calculation logic.
Fixed simple bugs from last commit. Still not working though.
New scoping logic is now working. However I had to work around a bug I don't know how to fix right now - calling update_stage to fetch the new data from the database is not working for some reason. I suspect a temporal coupling with the plugin manager somewhere.