addpermission code
refactoring