Add reusable permissioning. Fix testing bugs.