Fixed broken tests.
Refactored permission and tests.