First part of permission handling and related changes