added permission based restrictions on entities/entity attributes, refactoring