Added features to clean up permissions when nodes or individual permissions are removed.