Added configurable permissions, various cleanup