Index: accounts.php
===================================================================
--- accounts.php	(revision 7cf8a82618b144fc2c1d7fdf2bb233d0bb46b9ad)
+++ accounts.php	(revision 8214134c668c89f7c611da09569cfdd4d3c65a72)
@@ -1,9 +1,19 @@
 <?php
+
+// The paage that is loaded for account related functions
+
+// Include the main PHP file
 include ('include.php');
 
+// Set the page name for display purposes
 $page_name = "Meraki Administrators";
+// Set the page name in the template
+// TODO: Allow better per-page customisation of the template
 $page_header = preg_replace ( '/PAGE_NAME/', $page_name, $page_header );
 
+// Check to see if this is an API call or a new call to the page
+//TODO: This is no longer required.  All calls should now go to api.php.  Check, and then remove this code. 
 if ( !isset ( $_POST['action'] ) || $_POST['action'] == "" ) {
+	// Send the page to the browser
 	echo ( $page_header );
 	new_request();
@@ -11,8 +21,11 @@
 }
 else {
+	// API Call - Parse request in include.php
 	parse_request();
 }
 
-	function new_request() { 
+// Send the appropriate page to the browser	
+	function new_request() {
+		//If no specific page is requested, send a menu
 		if ( !isset ( $_GET['page'] ) || $_GET['page'] == "" ) { ?>
 		
@@ -26,4 +39,5 @@
 		<?php }
 		else {
+			// A specific page has been requested - send that one
 			switch ($_GET['page']) {
 				case "admins_by_org":
@@ -48,4 +62,6 @@
 
 	
+//Functions to return appropriate page based on switch statement above
+
 function page_admins_by_org() {	?>
 		<div class="meraki_admins_by_org" id="meraki_admins_by_org">
Index: api.php
===================================================================
--- api.php	(revision 7cf8a82618b144fc2c1d7fdf2bb233d0bb46b9ad)
+++ api.php	(revision 8214134c668c89f7c611da09569cfdd4d3c65a72)
@@ -1,8 +1,17 @@
 <?php
+
+//This file is simply a wrapper around include.php
+
+// Include the main PHP file
 include ('include.php');
+
+// Check to see if this is an API call or a new call to the page
+// We should only be dealing with API calls, so something is wrong if called
+// without an action
 if ( !isset ( $_POST['action'] ) || $_POST['action'] == "" ) {
 	die ('We shouldn\'t be here - something bad is happening');
 }
 else {
+    // API Call - Parse request in include.php
 	parse_request();
 }
Index: config.template.php
===================================================================
--- config.template.php	(revision 7cf8a82618b144fc2c1d7fdf2bb233d0bb46b9ad)
+++ config.template.php	(revision 8214134c668c89f7c611da09569cfdd4d3c65a72)
@@ -1,5 +1,14 @@
 <?php
+// Meraki Server base URL - this should be correct
+// Please include trailing /
+// Eg: $SERVER='https://dashboard.meraki.com/api/';
 $SERVER='https://dashboard.meraki.com/api/';
+
+// The API version we wish to use
+// This is used in the request URL so must be correct
 $API_VERSION='v0';
+
+// A Read Only API key that can be used to get general information without
+// a user specific key
 $RO_API_KEY='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
 ?>
Index: include.js
===================================================================
--- include.js	(revision 7cf8a82618b144fc2c1d7fdf2bb233d0bb46b9ad)
+++ include.js	(revision 8214134c668c89f7c611da09569cfdd4d3c65a72)
@@ -1,12 +1,27 @@
+// Variable to hold fetched organisations
 var orgs;
+
+// Variable to hold fetched networks
 var nets;
+
+// Number of Organisations expected
 var number_of_orgs;
+
+// Number of Networks expected
 var number_of_nets;
+
+// Number of Organisations fetched
 var orgs_completed=0;
+
+// Number of Networks fetched
 var nets_completed=0;
-var current_org=-1;
+
+// API Key
 var key="";
 
+// Initialisation functions
 $( document ).ready(function() {
+
+	// Add a handler to hide and show API key when a read only key is allowed
 	$("#meraki_ro_key").change(function(event) {
 		var checkbox = event.target;
@@ -14,24 +29,38 @@
 			$(".meraki_ro_key").hide();
 		} else {
+			// Cannot use normal jQuery function to show as it requires the
+			// display property set to table-row
 			$(".meraki_ro_key").css('display', 'table-row');
 		}
 	});
+
 });
 
 
-//ADMIN FUNCTIONS
-
+// ADMIN FUNCTIONS
+
+// Called by button click
 function get_admins_by_org() {
+	// Update the status box
     status_update("Fetching organisations...");
+	// Hide the form to prevent people clicking stuff
 	$(".meraki_form").hide();
+	// Get the key to use
 	set_key();
+	// Call the general function to get the list of organisations
+	// Using the success callback for this operation, and a general error catching callback
     get_organisations(on_get_organisations_success_admins, on_get_organisations_error);
 }
 
-
+// Callback from get_organisations which has succesfully returned data
 function on_get_organisations_success_admins(data) {
+	// Store the organisations received into the global variable
 	orgs = data;
+	// Get the number of organisations in the array
 	number_of_orgs = orgs.length;
+	// Update the status box
 	status_update("Found " + number_of_orgs + " organisations - fetching admins...");
+
+	// Get the admins for each organisation
     $.each(data, function(org) {
 
@@ -51,7 +80,16 @@
 }
 
+// Callback from AJAX call to get organisation admins which has succesfully returned data
 function on_get_admin_sucess(administrator, org_index) {
+	// Add the new information to the "administrator" object in
+	// the global organisation array
     orgs[org_index].administrator = administrator;
+
+	// Mark it as a completed call
 	orgs_completed++;
+
+	// Check whether all calls have now returned
+		// If they have, print the output
+		// Otherwise do nothing as we're still waiting on more data
     if(check_orgs_complete()) {
         print_admins_output();
@@ -59,8 +97,17 @@
 }
 
+// Callback from AJAX call to get organisation admins which has returned an error
 function on_get_admin_error(error, org_index) {
+	// Add a new "administrator" object in the global organisation
+	// array and mark it with an ERROR value
     orgs[org_index].administrator = [];
 	orgs[org_index].administrator[0] = "ERROR";
+
+	// Mark it as a completed call
 	orgs_completed++;
+
+	// Check whether all calls have now returned
+		// If they have, print the output
+		// Otherwise do nothing as we're still waiting on more data
     if(check_orgs_complete()) {
         print_admins_output();
@@ -68,5 +115,9 @@
 }
 
+// Print the output when the AJAX calls complete
 function print_admins_output() {
+	// Depending on the page we need to print the output differently
+	// The page is defined in a global variable in a script tag
+	// on the original HTML page
 	if ( page == "orgs_by_admin" ){
 		print_admins_output_by_admin();
@@ -82,11 +133,17 @@
 	}
 	else {
+		// We define the pages so there shouldn't be any missing
 		status_update("Errrrrr - this shouldn't ever be reached - something went very wrong!");
 	}
 }
 
+// Prints the list of administrators grouped by organisation
 function print_admins_output_by_org() {
 	status_update('Sorting and generating output...');
+
+	// Sort the organisations by name A -> Z
 	sorted = orgs.sort(function(a, b) { return a.name - b.name; });
+
+	// Insert the table into the pre-created div
 	$("#meraki_admins_output").html('\
 		<table class="meraki_output_table" id="meraki_admins_output_table">\
@@ -99,7 +156,13 @@
 		</table>\
 	');
+
+	// Loop over each organisation
 	$.each(sorted, function(data) {
+		// Check we suceeded in fetching the admins of the network
 		if ( sorted[data].administrator[0] != "ERROR" ) {
+			// Store the number of admins in this organisation
 			number_of_admins = sorted[data].administrator.length;
+			// Output the organisation with an appropriate row span along
+			// with the first admnistrator
 			$("#meraki_admins_output_table").append('\
 				<tr>\
@@ -110,4 +173,5 @@
 				</tr>\
 			');
+			// Loop oveer the remainig admins (note i=1 not 0) and output their details
 			for (i=1; i<number_of_admins; i++) {
 				$("#meraki_admins_output_table").append('\
@@ -121,4 +185,5 @@
 		}
 		else {
+			//We failed to get data on this organisation
 			$("#meraki_admins_output_table").append('\
 				<tr>\
@@ -131,13 +196,20 @@
 		}
 	});
+	//Entire function is complete
 	status_update("Done...");
 }
 
+// Prints the list of organisations grouped by oadministrator
 function print_admins_output_by_admin() {
 	status_update('Sorting and generating output...');
 	
+	// Call another function to group organisations by administrator
+	// as this is non-trivial and needed elsewhere
 	admins = group_orgs_by_admin();
-	
+
+	//TODO: Sort by admin alphabetically
 	sorted = admins; //.sort(function(a, b) { return a.name - b.name; });
+
+	// Insert the table into the pre-created div
 	$("#meraki_admins_output").html('\
 		<table class="meraki_output_table" id="meraki_admins_output_table">\
@@ -150,6 +222,12 @@
 		</table>\
 	');
+
+	// Loop over each administrator
 	$.each(sorted, function(j) {
+		// Store the number of organisations available to this admin
+		// TODO: Fix variable name but can't number_of_orgs (damn globals!)
 		number_of_admins = sorted[j].length;
+		// Output the admin with an appropriate row span along
+		// with the first organisation
 		$("#meraki_admins_output_table").append('\
 			<tr>\
@@ -160,4 +238,5 @@
 			</tr>\
 		');
+		// Loop oveer the remainig organisations (note i=1 not 0) and output their details
 		for (i=1; i<number_of_admins; i++) {
 			$("#meraki_admins_output_table").append('\
@@ -169,4 +248,5 @@
 		}
 	});
+	//Entire function is complete
 	status_update("Done...");
 }
@@ -177,8 +257,11 @@
 	sorted = orgs.sort(function(a, b) { return (a.name < b.name)?-1:((b.name < a.name)?1:0); });
 	orgs = sorted;
-
+	
+	// Call another function to group organisations by administrator
+	// as this is non-trivial and needed elsewhere
 	admins = group_orgs_by_admin();
 	
-	//check if admin exists - if not we can skip the per org checks
+	// Check if the admin exists in organisations this key manages
+	// If not we can skip the per organisation checks later
 	var admin_to_add = $('#meraki_email').val();
 	var admin_exists;
@@ -190,8 +273,9 @@
 	}
 	
+	// Add to the HTML page a prompt and the select all box
 	$('#meraki_orgsOutput').append('\
 		<div class="meraki_row"><p>Please select the organisations to add this user to:</p></div>\
 	');
-	$('#meraki_orgsOutput').append('<div class="meraki_row" id="meraki_orgs_select_all"></div');
+	$('#meraki_orgsOutput').append('<div class="meraki_row" id="meraki_orgs_select_all"></div>');
 	$('#meraki_orgs_select_all').append('\
 		<div class="meraki_left">\
@@ -207,12 +291,23 @@
 	');
 	
+	//  Attach a function to the check all box to be triggered when changed
 	$("#meraki_orgs_select_all_box").change(function(event) {
+
+		// Define the checkbox we're working on
 		var checkbox = event.target;
+		
+		// If it's checked, tick all the organisation checkboxes that are not disabled and not already checked
 		if (checkbox.checked) {
 			$(':checkbox[name="org_checkboxes[]"]:not(:disabled):not(:checked)').each( function () {
+				//Note: "this" is the current object in the "each" loop, not the object which raised the event
 				this.checked = true;
 			});
-		} else {
+		}
+		// Otherwise, untick all the organisation checkboxes that
+		// are not disabled and are already checked
+		else {
 			$(':checkbox[name="org_checkboxes[]"]:not(:disabled):checked').each( function () {
+				//Note: "this" is the current object in the "each" loop,
+				// not the object which raised the event
 				this.checked = false;
 			});
@@ -220,7 +315,9 @@
 	});
 
-
+	// Loop over the organisations
 	$.each (orgs, function (k) {
+		// Add a new row to the table
 		$('#meraki_orgsOutput').append('<div class="meraki_row" id="meraki_orgs_'+k+'"></div>');
+		// Print the name
 		$('#meraki_orgs_'+k).append('\
 			<div class="meraki_left">\
@@ -230,4 +327,5 @@
 			</div>\
 		');
+		// Print a checkbox with a value and DOM id based on the Meraki id
 		$('#meraki_orgs_'+k).append('\
 			<div class="meraki_middle">\
@@ -236,6 +334,11 @@
 		');
 		
+		// Add a status column
 		$('#meraki_orgs_'+k).append('<div class="meraki_right" id="meraki_org_output_'+orgs[k].id+'" ></div>');
-		
+
+		// If we were unable to query the admins for the organisation
+			// Disable the checkbox
+			// Add an error to the output column
+			// Set the formatting (CSS class)
 		if ( orgs[k].administrator == "ERROR") {
 			$('#meraki_org_'+orgs[k].id).attr('disabled','disabled');
@@ -244,6 +347,12 @@
 		}
 		
+		// If the admin exists
 		if ( admin_exists ) {
+			// Loop over administrators organisations
 			$.each ( admins[admin_to_add], function (j) {
+				//If this organisation is already there
+					// Disable the checkbox
+					// Add an error to the output column
+					// Set the formatting (CSS class)
 				if ( admins[admin_to_add][j].id == orgs[k].id ) {
 					$('#meraki_org_'+orgs[k].id).attr('disabled','disabled');
@@ -254,4 +363,6 @@
 		}
 	});
+
+	// Add a button to submit form
 	$('#meraki_orgsOutput').append('\
 		<div class="meraki_row">\
@@ -259,19 +370,31 @@
 		</div>\
 	');
+
+	// Need to wait for the user to click the button...
 	status_update('Waiting for user input...');
 }
-	
+
+// Function to add the admin to the selected organisations
 function add_admin() {
     status_update("Adding admins...");
+
+	// Hide the button to prevent double submissions
 	$("#meraki_go").hide();
 	
-
+	// Retrieve values from the form
 	var fname = $("#meraki_full_name").val();
 	var email = $("#meraki_email").val();
 	var orgaccess = $("#meraki_access").val();
 	
+	// Loop over selected check boxes in the org_checkboxes array
+	// Don't need to check for enabled as disabled ones are all unticked	
 	$(':checkbox[name="org_checkboxes[]"]:checked').each( function () {
-	var org_id = this.value;
-	$('#meraki_org_output_'+org_id).html('Adding...');
+		// Get the Meraki organisation id which was stored as the checkbox value
+		var org_id = this.value;
+
+		// Update the output column
+		$('#meraki_org_output_'+org_id).html('Adding...');
+
+		// Queue an AJAX call to add the admin to the organisation
 		$.ajax({
 			dataType: "json",
@@ -292,4 +415,5 @@
 }
 
+// Callback to update output column on success
 function on_add_admin_success(r, org_id) {
 	$('#meraki_org_output_'+org_id).html('Success')
@@ -297,4 +421,5 @@
 }
 
+// Callback to update output column on error
 function on_add_admin_error(e, org_id) {
 	$('#meraki_org_output_'+org_id).html('Error: '+e);
@@ -302,15 +427,23 @@
 }
 
+
 function print_select_admin_to_remove() {
 	status_update('Sorting and generating output...');
 	
+	// Call another function to group organisations by administrator
+	// as this is non-trivial and needed elsewhere
 	admins = group_orgs_by_admin();
 	
+	// Create list box for admins
 	$('#meraki_admins_output').html('<select id="meraki_admin" name="meraki_admin"></select>');
 	
+	// Loop over admins and add as an option in the list box
+	// The index for the admins object is email and this is used by
+	// JQuery as the iterator (j) 
 	$.each ( admins, function (j) {
 		$('#meraki_admin').append('<option value="'+j+'">'+j+' ('+this.name+')</option>');
 	});
 	
+	// Add a button to submit form
 	$('#meraki_admins_output').append('\
 		<div class="meraki_row">\
@@ -321,9 +454,12 @@
 }
 
+//TODO: Rename this function (print_orgs_to_remove_admin?)
 function get_orgs_for_admin() {
 	status_update('Sorting and generating output...');
 	
+	// Hide the previous form to prevent resubmission
 	$('#meraki_admins_output').hide();
 	
+	// Get the admin to remove from the select box
 	var admin_to_remove = $('#meraki_admin').val();
 	
@@ -331,10 +467,13 @@
 	orgs = sorted;
 
+	// Call another function to group organisations by administrator
+	// as this is non-trivial and needed elsewhere
 	admins = group_orgs_by_admin();
 	
+	// Add to the HTML page a prompt and the select all box
 	$('#meraki_orgs_output').append('\
 		<div class="meraki_row"><p>Please select the organisations to remove this user from:</p></div>\
 	');
-	$('#meraki_orgs_output').append('<div class="meraki_row" id="meraki_orgs_select_all"></div');
+	$('#meraki_orgs_output').append('<div class="meraki_row" id="meraki_orgs_select_all"></div>');
 	$('#meraki_orgs_select_all').append('\
 		<div class="meraki_left">\
@@ -350,12 +489,23 @@
 	');
 	
+	//  Attach a function to the check all box to be triggered when changed
 	$("#meraki_orgs_select_all_box").change(function(event) {
+		
+		// Define the checkbox we're working on
 		var checkbox = event.target;
+		
+		// If it's checked, tick all the organisation checkboxes that are not disabled and not already checked
 		if (checkbox.checked) {
 			$(':checkbox[name="org_checkboxes[]"]:not(:disabled):not(:checked)').each( function () {
+				//Note: "this" is the current object in the "each" loop, not the object which raised the event
 				this.checked = true;
 			});
-		} else {
+		}
+		// Otherwise, untick all the organisation checkboxes that
+		// are not disabled and are already checked
+		else {
 			$(':checkbox[name="org_checkboxes[]"]:not(:disabled):checked').each( function () {
+				// Note: "this" is the current object in the "each" loop,
+				// not the object which raised the event
 				this.checked = false;
 			});
@@ -364,7 +514,9 @@
 
 
-
+	// Loop over the organisations
 	$.each (orgs, function (k) {
+		// Add a new row to the table
 		$('#meraki_orgs_output').append('<div class="meraki_row" id="meraki_orgs_'+k+'"></div>');
+		// Print the name
 		$('#meraki_orgs_'+k).append('\
 			<div class="meraki_left">\
@@ -374,4 +526,5 @@
 			</div>\
 		');
+		// Print a checkbox with a value and DOM id based on the Meraki id
 		$('#meraki_orgs_'+k).append('\
 			<div class="meraki_middle">\
@@ -380,4 +533,6 @@
 		');
 		
+		// Add a status column
+		// We assume they're not an admin and set the formatting
 		$('#meraki_orgs_'+k).append('<div class="meraki_right" id="meraki_org_output_'+orgs[k].id+'" ></div>');
 		$('#meraki_org_output_'+orgs[k].id).html('Not an admin');
@@ -385,4 +540,8 @@
 		$('#meraki_orgs_'+k).hide();
 		
+		// If we were unable to query the admins for the organisation
+			// Disable the checkbox
+			// Add an error to the output column
+			// Set the formatting (CSS class)
 		if ( orgs[k].administrator == "ERROR") {
 			$('#meraki_org_'+orgs[k].id).attr('disabled','disabled');
@@ -391,6 +550,11 @@
 			$('#meraki_orgs_'+k).hide();
 		}
-		
+	
+		// Loop over administrators organisations
 		$.each ( admins[admin_to_remove], function (j) {
+			//If this organisation is there
+					// Enable the checkbox
+					// Clear the output column
+					// Remove the formatting (CSS class)
 			if ( admins[admin_to_remove][j].id == orgs[k].id ) {
 				$('#meraki_org_'+orgs[k].id).removeAttr('disabled');
@@ -402,4 +566,6 @@
 		});
 	});
+	
+	// Add a button to submit form
 	$('#meraki_orgs_output').append('\
 		<div class="meraki_row">\
@@ -407,17 +573,28 @@
 		</div>\
 	');
+	
+	// Need to wait for the user to click the button...
 	status_update('Waiting for user input...');
 }
 
+// Function to remove the admin from the selected organisations
 function remove_admin() {
     status_update("Removing admin...");
+	
+	// Hide the button to prevent double submissions
 	$("#meraki_go").hide();
 	
-
+	// Loop over selected check boxes in the org_checkboxes array
+	// Don't need to check for enabled as disabled ones are all unticked
 	$(':checkbox[name="org_checkboxes[]"]:checked').each( function () {
-	var ids = this.value.split(':');
-	var org_id = ids[0];
-	var admin_id = ids[1];
-	$('#meraki_org_output_'+org_id).html('Removing...');
+		// Get the Meraki organisation and admin id which were stored in the checkbox value seperated by :
+		var ids = this.value.split(':');
+		var org_id = ids[0];
+		var admin_id = ids[1];
+		
+		// Update the output column
+		$('#meraki_org_output_'+org_id).html('Removing...');
+		
+		// Queue an AJAX call to remove the admin from the organisation
 		$.ajax({
 			dataType: "json",
@@ -435,4 +612,5 @@
 }
 
+// Callback to update output column on success
 function on_del_admin_success(r, org_id) {
 	$('#meraki_org_output_'+org_id).html('Success')
@@ -440,4 +618,5 @@
 }
 
+// Callback to update output column on error
 function on_del_admin_error(e, org_id) {
 	$('#meraki_org_output_'+org_id).html('Error: '+e);
@@ -448,25 +627,35 @@
 //GET INVENTORY
 
+// Called by button click
 function get_inv_orgs() {
-	
+	// Update the status box
 	status_update("Fetching organisations...");
+	// Hide the form to prevent people clicking stuff
 	$(".meraki_form").hide();
+	// Get the key to use
 	set_key();
+	// Call the general function to get the list of organisations
+	// Using the success callback for this operation, and a general error catching callback
 	get_organisations(on_get_organisations_success_inventory, on_get_organisations_error);	
 }
 
+// Callback from get_organisations which has succesfully returned data
 function on_get_organisations_success_inventory(data) {
+	// Update the status box
 	status_update('Sorting and generating output...');
-
+	// Store the organisations received into the global variable
 	orgs = data;
+	// Sort the organisations by name A - Z
 	sorted = orgs.sort(function(a, b) { return (a.name < b.name)?-1:((b.name < a.name)?1:0); });
 	
-	
+	// Create list box for organisations
 	$('#meraki_orgs_output').html('<select id="meraki_org" name="meraki_org"></select>');
 	
+	// Loop over organisations and add as an option in the list box
 	$.each ( orgs, function (j) {
 		$('#meraki_org').append('<option value="'+this.id+'">'+this.name+'</option>');
 	});
 	
+	// Add a button to submit form
 	$('#meraki_orgs_output').append('\
 		<div class="meraki_row">\
@@ -477,8 +666,14 @@
 }
 
+// Called by button click
+// TODO: Rename this function
 function get_inventory() {
+	// Update the status box
 	status_update("Fetching networks...");
+	// Hide the form to prevent people clicking stuff
 	$('#meraki_orgs_output').hide();
+	// Get the organisation id to use
 	var orgid=$('#meraki_org').val();
+	// Get the networks in this organisation
 	$.ajax({
 		dataType: "json",
@@ -495,4 +690,5 @@
 }
 
+// Callback from AJAX call to get organisation networks which has succesfully returned data
 function on_get_network_success(r, orgid) {
 	nets = r;
@@ -500,4 +696,5 @@
 	status_update("Found " + number_of_nets + " networks - fetching device details...");
 	
+	// Get the devices for each network
     $.each(r, function(network) {
         $.ajax({
@@ -517,4 +714,5 @@
 }
 
+// Callback from AJAX call to get network devices which has succesfully returned data
 function on_get_devices_success(devices, net_index) {
 	nets[net_index].devices = devices;
Index: include.php
===================================================================
--- include.php	(revision 7cf8a82618b144fc2c1d7fdf2bb233d0bb46b9ad)
+++ include.php	(revision 8214134c668c89f7c611da09569cfdd4d3c65a72)
@@ -1,9 +1,15 @@
 <?php
 
+// Main PHP file containing most of the functionality required
+
+// Populate configuration variables with local values
 include 'config.php';
 
+// Load in the header and footer for the HTML pages
 $page_header = file_get_contents ( "page_header.html" );
 $page_footer = file_get_contents ( "page_footer.html" );
 
+// Function to add a row to the forms with the standard fields for
+// The API key where using the built in read only key would be acceptable
 function ro_key_fields() { ?>
 				<div class="meraki_row">
@@ -25,4 +31,7 @@
 <?php }
 
+// Function to add a row to the forms with the standard fields for
+// The API key where using the built in read only key would NOT be acceptable
+// This is generally where people need to make changes
 function rw_key_fields() { ?>
 				<div class="meraki_row meraki_rw_key">
@@ -38,8 +47,9 @@
 
 
-
+	// Parse API calls
 	function parse_request() {
 		global $RO_API_KEY;
-		
+	
+		// If a key is sent, use that one, otherwise use the readonly key	
 		if ( !isset ( $_POST['key'] ) || $_POST['key'] == "" || $_POST['key'] == "rokey" ) {
 			$key = $RO_API_KEY;
@@ -49,6 +59,8 @@
 		}
 		
+		// Truncate the key for logging so we can see who's using who's key
 		$truncated_key = preg_replace ( '/^[0-9a-fA-F]{36}/', '******', $key );
 		
+		// Switch on the action requested, log the request and reply with the return value of the appropriate function
 		switch ($_POST['action']) {
 			case "get_orgs":
@@ -93,58 +105,35 @@
 
 
-	//Get a list of organisations
+	// Get a list of organisations
 	function get_orgs($key) {
 		return get_request('/organizations/', $key);
 	}
 	
-	//Get a list of networks in an organisation
+	// Get a list of networks in an organisation
 	function get_org_networks($orgid, $key) {
 		return get_request('/organizations/' . $orgid . '/networks', $key);
 	}
 	
-	//Get a list of devices in an organisation
+	// Get a list of devices in an organisation
 	function get_network_devices($orgid, $netid, $key) {
 		return get_request('/networks/' . $netid . '/devices', $key);
 	}
 
-	//Get an array of licences for an organisation
+	// Get an array of licences for an organisation
 	function get_org_licences($orgid, $key) {
 		return get_request('/organizations/' . $orgid . '/licenseState', $key );
 	}
 		
-	//Get a list of APs in a network
+	// Get a list of APs in a network
 	function get_net_aps($netid, $key) {
 		return get_request('/networks/' . $netid . '/devices', $key );
 	}
 	
-	//Get a list of admins in an organisation
+	// Get a list of admins in an organisation
 	function get_org_admins($orgid, $key) {
 		return get_request('/organizations/' . $orgid . '/admins', $key );
 	}
-	//SAMPLE RESPONSE
-	//[
-	// {
-	//	"id":"1",
-	//	"name":"Miles Meraki",
-	//	"email":"miles@meraki.com",
-	//	"orgAccess":"none",
-	//	"tags":[
-	//	  {
-	//		"tag":"west",
-	//		"access":"read-only"
-	//	  }
-	//	],
-	//	"networks":[
-	//	  {
-	//		"id":"N_249",
-	//		"access":"full"
-	//	  }
-	//	]
-	//  }
-	//]
-	
-	//Add Admin
-	//POST /organizations/[organization_id]/admins
-	//sample post data:
+	
+	// Add and admin to and organisation
 	function add_org_admin($orgid, $name, $email, $access, $key) {
 		$data = array ("name" => $name, "email" => $email, "orgAccess" => $access);
@@ -153,5 +142,5 @@
 	}
 	
-	//Delete an admin from an organisation
+	// Delete an admin from an organisation
 	function delete_org_admin($orgid, $adminid, $key) {
 		return delete_request('/organizations/' . $orgid . '/admins/' . $adminid, $key);
@@ -162,10 +151,10 @@
 	
 	
-	//General function to submit a GET call
+	// General function to submit a GET call
 	function get_request($call, $key) {
 		global $SERVER;
 		global $API_VERSION;
 	
-		//TODO: Move to CURL
+		// TODO: Move to CURL
 
 		$opts = array(
@@ -180,31 +169,54 @@
 		// Open the file using the HTTP headers set above
 		$json = file_get_contents($SERVER . $API_VERSION . $call, false, $context);
-		//TODO:  Catch exceptions and return errors
+		// TODO:  Catch exceptions and return errors
+
+		// Sanitise the ID for Javascript (enclose in " so it's a string rather than a number)
 		$resp = preg_replace ( '/"id":([0-9]+),/', '"id":"$1",', $json );
 		return $resp;
 	}
 
-	//General function to submit a POST call
+	// General function to submit a POST call
 	function post_request($call, $data, $key) {
+
+		// Use the values defined in the config.php file
 		global $SERVER;
 		global $API_VERSION;
 		
+		// Initialise curl
 		$ch = curl_init();
+
+		// Set the request URL
 		curl_setopt($ch, CURLOPT_URL,$SERVER . $API_VERSION . $call);
+		// Define a POST request
 		curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
+		// Follow redirects
 		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
-		curl_setopt($ch, CURLOPT_POSTFIELDS,json_encode($data));  //Post Fields
+		// Encode the data to be sent and attach to the request
+		curl_setopt($ch, CURLOPT_POSTFIELDS,json_encode($data));
+		// Return the result of request instead of Truse/False
 		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+
+		// Define request headers
 		$headers = [	"X-Cisco-Meraki-API-Key: " . $key,
 						"Content-type: application/json"
 					];
+
+		// Attach the headers to the request
 		curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
 
+		// Execute the curl request and get the returned data and HTTP code
 		$json = curl_exec ($ch);
 		$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
 		
+		// Sanitise the ID for Javascript (enclose in " so it's a string rather than a number)
 		$resp = preg_replace ( '/"id":([0-9]+),/', '"id":"$1",', $json );
+
+		// Tidy up
 		curl_close ($ch);
+
+		// Send the return code back to the requesting browser
 		header('HTTP/1.1 ' . $httpcode);
+
+		// Send any data we may or may not have
 		return $resp;
 	}
@@ -212,24 +224,44 @@
 	//General function to submit a DELETE call
 	function delete_request($call, $key) {
+
+		// Use the values defined in the config.php file
 		global $SERVER;
 		global $API_VERSION;
 
 
+		// Initialise curl
 		$ch = curl_init();
+
+		// Set the request URL
 		curl_setopt($ch, CURLOPT_URL,$SERVER . $API_VERSION . $call);
+		// Define a DELETE request
 		curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
+		// Follow redirects
 		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
+		// Return the result of request instead of Truse/False
 		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+
+		// Define request headers
 		$headers = [	"X-Cisco-Meraki-API-Key: " . $key,
 						"Content-type: application/json"
 					];
+
+		// Attach the headers to the request
 		curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
 
+		// Execute the curl request and get the returned data and HTTP code
 		$json = curl_exec ($ch);
 		$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
 		
+		// Sanitise the ID for Javascript (enclose in " so it's a string rather than a number)
 		$resp = preg_replace ( '/"id":([0-9]+),/', '"id":"$1",', $json );
+
+		// Tidy up
 		curl_close ($ch);
+
+		// Send the return code back to the requesting browser
 		header('HTTP/1.1 ' . $httpcode);
+
+		// Send any data we may or may not have
 		return $resp;
 	}
Index: inventory.php
===================================================================
--- inventory.php	(revision 7cf8a82618b144fc2c1d7fdf2bb233d0bb46b9ad)
+++ inventory.php	(revision 8214134c668c89f7c611da09569cfdd4d3c65a72)
@@ -1,9 +1,19 @@
 <?php
+
+// The paage that is loaded for account related functions
+
+// Include the main PHP file
 include ('include.php');
 
+// Set the page name for display purposes
 $page_name = "Meraki Inventory";
+// Set the page name in the template
+// TODO: Allow better per-page customisation of the template
 $page_header = preg_replace ( '/PAGE_NAME/', $page_name, $page_header );
 
+// Check to see if this is an API call or a new call to the page
+//TODO: This is no longer required.  All calls should now go to api.php.  Check, and then remove this code.
 if ( !isset ( $_POST['action'] ) || $_POST['action'] == "" ) {
+    // Send the page to the browser
 	echo ( $page_header );
 	new_request();
@@ -11,32 +21,33 @@
 }
 else {
+    // API Call - Parse request in include.php
 	parse_request();
 }
 
-	function new_request() { ?>
+// Send the page to the browser
+function new_request() { ?>
+	
+	<div class="meraki_licence_state" id="meraki_licence_state">
+		<h2>Inventory of Organisation</h2>
+		<div id="meraki_status"><pre>Current status: Awaiting user input</pre></div>
+			<div class="meraki_container meraki_form">
+			<?php ro_key_fields(); ?>
+			<input type="button" class="meraki_button" name="meraki_next1" id="meraki_next1" value="Next" onclick="get_inv_orgs();">
+		</div>
 		
-		<div class="meraki_licence_state" id="meraki_licence_state">
-			<h2>Inventory of Organisation</h2>
-			<div id="meraki_status"><pre>Current status: Awaiting user input</pre></div>
-
-			<div class="meraki_container meraki_form">
-				<?php ro_key_fields(); ?>
-				<input type="button" class="meraki_button" name="meraki_next1" id="meraki_next1" value="Next" onclick="get_inv_orgs();">
-			</div>
-			
-			<div id="meraki_orgs_output"></div>
-			
-			<div id="meraki_inventory_output"></div>
-		</div>
+		<div id="meraki_orgs_output"></div>
+		
+		<div id="meraki_inventory_output"></div>
+	</div>
 			
 
 
 		
-		<script>
-			var page = "inventory";
-		</script>
-		<?php
-		return;
-	}
+	<script>
+		var page = "inventory";
+	</script>
+	<?php
+	return;
+}
 
 ?>
Index: licences.php
===================================================================
--- licences.php	(revision 7cf8a82618b144fc2c1d7fdf2bb233d0bb46b9ad)
+++ licences.php	(revision 8214134c668c89f7c611da09569cfdd4d3c65a72)
@@ -1,9 +1,19 @@
 <?php
+
+// The paage that is loaded for account related functions
+
+// Include the main PHP file
 include ('include.php');
 
+// Set the page name for display purposes
 $page_name = "Meraki Licencing";
+// Set the page name in the template
+// TODO: Allow better per-page customisation of the template
 $page_header = preg_replace ( '/PAGE_NAME/', $page_name, $page_header );
 
+// Check to see if this is an API call or a new call to the page
+//TODO: This is no longer required.  All calls should now go to api.php.  Check, and then remove this code.
 if ( !isset ( $_POST['action'] ) || $_POST['action'] == "" ) {
+    // Send the page to the browser
 	echo ( $page_header );
 	new_request();
@@ -11,34 +21,35 @@
 }
 else {
+    // API Call - Parse request in include.php
 	parse_request();
 }
 
-	function new_request() { ?>
-		
-		<div class="meraki_licence_state" id="meraki_licence_state">
-			<h2>Licence State for Organisations</h2>
-			<div id="meraki_status"><pre>Current status: Awaiting user input</pre></div>
-
+// Send the page to the browser
+function new_request() { ?>
+	
+	<div class="meraki_licence_state" id="meraki_licence_state">
+		<h2>Licence State for Organisations</h2>
+		<div id="meraki_status"><pre>Current status: Awaiting user input</pre></div>
 			<div class="meraki_container meraki_form">
-				<?php ro_key_fields(); ?>
-				<div class="meraki_row">
-					<div class="meraki_left">
-						<input type="button" class="meraki_button" name="meraki_go" id="meraki_go" value="Fetch Licence State" onclick="get_licence_state();">
-					</div>
+			<?php ro_key_fields(); ?>
+			<div class="meraki_row">
+				<div class="meraki_left">
+					<input type="button" class="meraki_button" name="meraki_go" id="meraki_go" value="Fetch Licence State" onclick="get_licence_state();">
 				</div>
 			</div>
-			
-			<div id="meraki_licence_output"></div>
 		</div>
+		
+		<div id="meraki_licence_output"></div>
+	</div>
 			
 
 
 		
-		<script>
-			
-		</script>
-		<?php
-		return;
-	}
+	<script>
+		
+	</script>
+	<?php
+	return;
+}
 
 ?>
