fix permissions logic
factor permission handling back together