Abstracted out most of the security check for application/template permission to an allowed_templates function which checks both the Application ID (if present) and the Template ID to ensure it's either public or the user has explicit permission to perform a given task; Stubbed out sanitize_boolean and sanitize_array;
Implemented Boolean santization;