added permission checking