Committed some small fix.
Some improvements to permission checking.