Fix permission bugs