Improved permissions checking.