rewrite some patches, now usable in any build configuration. Added some permissions, need to filter them still