Make PackScope correctly retain objects.
Refactor entity and property security checks to allow custom implementations to be injected.