Fix bugs with permissions