diff --git a/backup/moodle2/backup_gradingform_guide_plugin.class.php b/backup/moodle2/backup_gradingform_guide_plugin.class.php
index a78931c..fee6e6b 100644
--- a/backup/moodle2/backup_gradingform_guide_plugin.class.php
+++ b/backup/moodle2/backup_gradingform_guide_plugin.class.php
@@ -26,11 +26,16 @@ defined('MOODLE_INTERNAL') || die();
 
 /**
  * Defines marking guide backup structures
+ *
+ * @package    gradingform_guide
+ * @copyright  2012 Dan Marsden <dan@danmarsden.com>
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 class backup_gradingform_guide_plugin extends backup_gradingform_plugin {
 
     /**
      * Declares marking guide structures to append to the grading form definition
+     * @return backup_plugin_element
      */
     protected function define_definition_plugin_structure() {
 
@@ -45,15 +50,15 @@ class backup_gradingform_guide_plugin extends backup_gradingform_plugin {
 
         // Define our elements
 
-        $criteria = new backup_nested_element('criteria');
+        $criteria = new backup_nested_element('guidecriteria');
 
-        $criterion = new backup_nested_element('criterion', array('id'), array(
+        $criterion = new backup_nested_element('guidecriterion', array('id'), array(
             'sortorder', 'shortname', 'description', 'descriptionformat',
             'descriptionmarkers', 'descriptionmarkersformat', 'maxscore'));
 
-        $comments = new backup_nested_element('comments');
+        $comments = new backup_nested_element('guidecomments');
 
-        $comment = new backup_nested_element('comment', array('id'), array(
+        $comment = new backup_nested_element('guidecomment', array('id'), array(
             'sortorder', 'description', 'descriptionformat'));
 
         // Build elements hierarchy
@@ -79,6 +84,7 @@ class backup_gradingform_guide_plugin extends backup_gradingform_plugin {
 
     /**
      * Declares marking guide structures to append to the grading form instances
+     * @return backup_plugin_element
      */
     protected function define_instance_plugin_structure() {
 
diff --git a/backup/moodle2/restore_gradingform_guide_plugin.class.php b/backup/moodle2/restore_gradingform_guide_plugin.class.php
index 6e83627..dd99814 100644
--- a/backup/moodle2/restore_gradingform_guide_plugin.class.php
+++ b/backup/moodle2/restore_gradingform_guide_plugin.class.php
@@ -26,6 +26,10 @@ defined('MOODLE_INTERNAL') || die();
 
 /**
  * Restores the marking guide specific data from grading.xml file
+ *
+ * @package    gradingform_guide
+ * @copyright  2012 Dan Marsden <dan@danmarsden.com>
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 class restore_gradingform_guide_plugin extends restore_gradingform_plugin {
 
@@ -39,10 +43,10 @@ class restore_gradingform_guide_plugin extends restore_gradingform_plugin {
         $paths = array();
 
         $paths[] = new restore_path_element('gradingform_guide_criterion',
-            $this->get_pathfor('/criteria/criterion'));
+            $this->get_pathfor('/guidecriteria/guidecriterion'));
 
         $paths[] = new restore_path_element('gradingform_guide_comment',
-            $this->get_pathfor('/comments/comment'));
+            $this->get_pathfor('/guidecomments/guidecomment'));
 
         return $paths;
     }
@@ -67,6 +71,8 @@ class restore_gradingform_guide_plugin extends restore_gradingform_plugin {
      *
      * Sets the mapping 'gradingform_guide_criterion' to be used later by
      * {@link self::process_gradinform_guide_filling()}
+     *
+     * @param array|stdClass $data
      */
     public function process_gradingform_guide_criterion($data) {
         global $DB;
@@ -82,6 +88,7 @@ class restore_gradingform_guide_plugin extends restore_gradingform_plugin {
     /**
      * Processes comments element data
      *
+     * @param array|stdClass $data The data to insert as a comment
      */
     public function process_gradingform_guide_comment($data) {
         global $DB;
@@ -94,6 +101,8 @@ class restore_gradingform_guide_plugin extends restore_gradingform_plugin {
 
     /**
      * Processes filling element data
+     *
+     * @param array|stdClass $data The data to insert as a filling
      */
     public function process_gradinform_guide_filling($data) {
         global $DB;
diff --git a/guideeditor.php b/guideeditor.php
index add8c2e..de1edd7 100644
--- a/guideeditor.php
+++ b/guideeditor.php
@@ -15,6 +15,8 @@
 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
 
 /**
+ * This file contains the marking guide editor element
+ *
  * @package    gradingform_guide
  * @copyright  2012 Dan Marsden <dan@danmarsden.com>
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
@@ -25,23 +27,27 @@ defined('MOODLE_INTERNAL') || die();
 require_once("HTML/QuickForm/input.php");
 
 /**
+ * The editor for the marking guide advanced grading plugin.
+ *
  * @package    gradingform_guide
  * @copyright  2012 Dan Marsden <dan@danmarsden.com>
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 class moodlequickform_guideeditor extends HTML_QuickForm_input {
-    /** help message */
+    /** @var string help message */
     public $_helpbutton = '';
-    /** stores the result of the last validation: null - undefined, false - no errors, string - error(s) text */
+    /** @var null|false|string stores the result of the last validation: null - undefined, false - no errors, string - error(s) text */
     protected $validationerrors = null;
-    /** if element has already been validated **/
+    /** @var bool if element has already been validated **/
     protected $wasvalidated = false;
-    /** If non-submit (JS) button was pressed: null - unknown, true/false - button was/wasn't pressed */
+    /** @var null|bool If non-submit (JS) button was pressed: null - unknown, true/false - button was/wasn't pressed */
     protected $nonjsbuttonpressed = false;
-    /** Message to display in front of the editor (that there exist grades on this guide being edited) */
+    /** @var string|false Message to display in front of the editor (that there exist grades on this guide being edited) */
     protected $regradeconfirmation = false;
 
     /**
+     * Constructor
+     *
      * @param string $elementname
      * @param string $elementlabel
      * @param array $attributes
@@ -53,7 +59,6 @@ class moodlequickform_guideeditor extends HTML_QuickForm_input {
     /**
      * get html for help button
      *
-     * @access   public
      * @return  string html for help button
      */
     public function getHelpButton() {
@@ -339,7 +344,7 @@ class moodlequickform_guideeditor extends HTML_QuickForm_input {
      * Prepares the data for saving
      * @see prepare_data()
      *
-     * @param array $submitValues
+     * @param array $submitvalues
      * @param boolean $assoc
      * @return array
      */
diff --git a/lang/en/gradingform_guide.php b/lang/en/gradingform_guide.php
index 5e110c1..77c1391 100644
--- a/lang/en/gradingform_guide.php
+++ b/lang/en/gradingform_guide.php
@@ -15,6 +15,8 @@
 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
 
 /**
+ * Strings for the marking guide advanced grading plugin
+ *
  * @package    gradingform_guide
  * @copyright  2012 Dan Marsden <dan@danmarsden.com>
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
diff --git a/lib.php b/lib.php
index 6cba725..84a0bd7 100644
--- a/lib.php
+++ b/lib.php
@@ -298,7 +298,14 @@ class gradingform_guide_controller extends gradingform_controller {
         }
 
         //get definition
-        $this->definition = $DB->get_record('grading_definitions', array('areaid' => $this->areaid, 'method' => $this->get_method_name()), '*');
+        $definition = $DB->get_record('grading_definitions', array('areaid' => $this->areaid, 'method' => $this->get_method_name()), '*');
+        if (!$definition) {
+            // The definition doesn't have to exist. It may be that we are only now creating it.
+            $this->definition = false;
+            return false;
+        }
+
+        $this->definition = $definition;
         //now get criteria
         $this->definition->guide_criteria = array();
         $this->definition->guide_comment = array();
diff --git a/renderer.php b/renderer.php
index 91e988a..8f0fe30 100644
--- a/renderer.php
+++ b/renderer.php
@@ -48,7 +48,7 @@ class gradingform_guide_renderer extends plugin_renderer_base {
      * Also JavaScript relies on the class names of elements and when developer changes them
      * script might stop working.
      *
-     * @param int $mode guide display mode, one of gradingform_guide_controller::DISPLAY_* {@see gradingform_guide_controller}
+     * @param int $mode guide display mode, one of gradingform_guide_controller::DISPLAY_* {@link gradingform_guide_controller()}
      * @param array $options An array of options.
      *      showmarkspercriterionstudents (bool) If true adds the current score to the display
      * @param string $elementname the name of the form element (in editor mode) or the prefix for div ids (in view mode)
@@ -227,7 +227,7 @@ class gradingform_guide_renderer extends plugin_renderer_base {
      * Also JavaScript relies on the class names of elements and when developer changes them
      * script might stop working.
      *
-     * @param int $mode guide display mode, one of gradingform_guide_controller::DISPLAY_* {@see gradingform_guide_controller}
+     * @param int $mode guide display mode, one of gradingform_guide_controller::DISPLAY_* {@link gradingform_guide_controller}
      * @param string $elementname the name of the form element (in editor mode) or the prefix for div ids (in view mode)
      * @param array $comment
      * @return string
@@ -303,8 +303,8 @@ class gradingform_guide_renderer extends plugin_renderer_base {
      * Also JavaScript relies on the class names of elements and when developer changes them
      * script might stop working.
      *
-     * @param int $mode guide display mode, one of gradingform_guide_controller::DISPLAY_* {@see gradingform_guide_controller}
-     * @param array $options An array of options provided to {@see gradingform_guide_renderer::guide_edit_options()}
+     * @param int $mode guide display mode, one of gradingform_guide_controller::DISPLAY_* {@link gradingform_guide_controller}
+     * @param array $options An array of options provided to {@link gradingform_guide_renderer::guide_edit_options()}
      * @param string $elementname the name of the form element (in editor mode) or the prefix for div ids (in view mode)
      * @param string $criteriastr evaluated templates for this guide's criteria
      * @param string $commentstr
@@ -369,7 +369,7 @@ class gradingform_guide_renderer extends plugin_renderer_base {
      * Generates html template to view/edit the guide options. Expression {NAME} is used in
      * template for the form element name
      *
-     * @param int $mode guide display mode, one of gradingform_guide_controller::DISPLAY_* {@see gradingform_guide_controller}
+     * @param int $mode guide display mode, one of gradingform_guide_controller::DISPLAY_* {@link gradingform_guide_controller}
      * @param array $options
      * @return string
      */
@@ -442,7 +442,7 @@ class gradingform_guide_renderer extends plugin_renderer_base {
      * @param array $criteria data about the guide design
      * @param array $comments
      * @param array $options
-     * @param int $mode guide display mode, one of gradingform_guide_controller::DISPLAY_* {@see gradingform_guide_controller}
+     * @param int $mode guide display mode, one of gradingform_guide_controller::DISPLAY_* {@link gradingform_guide_controller}
      * @param string $elementname the name of the form element (in editor mode) or the prefix for div ids (in view mode)
      * @param array $values evaluation result
      * @param array $validationerrors
diff --git a/version.php b/version.php
index e235f71..91ca0ed 100644
--- a/version.php
+++ b/version.php
@@ -15,6 +15,8 @@
 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
 
 /**
+ * Marking guide, advanced grade plugin
+ *
  * @package    gradingform_guide
  * @copyright  2012 Dan Marsden <dan@danmarsden.com>
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
@@ -25,4 +27,4 @@ defined('MOODLE_INTERNAL') || die();
 $plugin->component  = 'gradingform_guide';
 $plugin->version    = 2012022100;
 $plugin->requires   = 2011110200;
-$plugin->maturity   = MATURITY_STABLE;
+$plugin->maturity   = MATURITY_STABLE;
\ No newline at end of file
