For #465, little tidying and handle some potential issues when scanning for permissions