Updated code with security permission