Added permission check and environment variable