CORE-3969: changed the way that permission cleanup is handled