           directive = override.directive
 
       $scope.setOptions(resource, item, formMode, wizardMaxDepth, parent, directive)
+      $scope.finish()
 
     else
 
       $scope.log("singlePage branch")
       $scope.csWizardOptions = {}
       # TODO Check if all the parameters arrived
-      # { resourceType, id, pageType}
-      resource_type = $scope.resourceType
+      # { resourceType, itemId, pageType}
       formMode = $scope.pageType 
       if formMode != 'show' && formMode != 'edit'
-        $scope.finish("'" + formMode + "' is not a valid page type!")
+        $scope.finish("'" + formMode + "' is not a valid page type!")#
+
+      resource_type = $scope.resourceType
       $scope.csWizardOptions['form-mode'] = formMode
       wizardMaxDepth = 5
       csDescriptorService.getPromises()
       .then(()->
-        return ResourceService.get($scope.resourceType)
-      ).catch((error) ->
-        errorMsg = "\"" + $scope.resourceType + "\" is not a registered resource"
-        $scope.finish(errorMsg)
-      ).then((_resource_) ->
-          resource = angular.copy(_resource_)
-          # Getting the resourc data
-          resource.$get($scope.itemId, {include: '*'})
-      ).catch((reason) ->
-          # TODO process the reason
-          errorMsg = "There is no " + resource.descriptor.name + " with the id: " + $scope.itemId
-          $scope.finish(errorMsg)
-      ).then((_item_)->
+        try
+          _resource_ = ResourceService.get($scope.resourceType)
+        catch error
+          errorMsg = "'" + $scope.resourceType + "' is not a registered resource."
+          $scope.finish(error)
+
+        resource = angular.copy(_resource_)
+        # Getting the resource data
+        resource.$get($scope.itemId, {include: '*'})
+        .then((_item_)->
+
           item = _item_
-      ).then( ()->
-        #Setting events
-        wizardCanceled = (() ->
-          csRoute.go("index", {resourceType : resource.descriptor.type})
-        ).bind(resource)
-
-        wizardSubmitted =  (()->
-          switch(formMode)
-            when "create" then csAlertService.success('new_resource_created')
-            when "edit" then csAlertService.success("changes_saved")
-          csRoute.go("index", {resourceType : resource.descriptor.type})
-        ).bind(formMode, resource)
-
-        $scope.csWizardOptions.events = {
-          'wizard-canceled' : wizardCanceled
-          'wizard-submitted' : wizardSubmitted
-        }
-        $scope.setOptions(resource, item, formMode, wizardMaxDepth)
+          #Setting events
+          wizardCanceled = (() ->
+            csRoute.go("index", {resourceType : resource.descriptor.type})
+          ).bind(resource)
+
+          wizardSubmitted =  (()->
+            switch(formMode)
+              when "create" then csAlertService.success('new_resource_created')
+              when "edit" then csAlertService.success("changes_saved")
+            csRoute.go("index", {resourceType : resource.descriptor.type})
+          ).bind(formMode, resource)
+
+          $scope.csWizardOptions.events = {
+            'wizard-canceled' : wizardCanceled
+            'wizard-submitted' : wizardSubmitted
+          }
+          $scope.setOptions(resource, item, formMode, wizardMaxDepth)
+          $scope.finish()
+
+        ).catch((reason) ->
+            # TODO process the reason
+            errorMsg = "There is no " + resource.descriptor.name + " with the id: " + $scope.itemId
+            $scope.finish(errorMsg)
+        )
+
     )
 
     if $scope.panelNumberCallback

        directive : directive
      }
      $scope.panelStack = [panelDescriptor]
      $scope.finish()

    $scope.finish = (error)->

      #console.log("Watchers")
      #console.log($scope.$$watchers)
      # Interesting
      # Without this $scope.$apply the form is loaded really slowly
      # or not at all.
      #$scope.$apply( ()->
      $scope.log("finish")
      $scope.loading = false
      $scope.errors.push(error) if error
      throw new Error(error) if error
      #)

    if $scope.csWizardOptions



  link = ($scope, element, attrs, controller) ->

    ValidationError = () ->
    ValidationError.prototype = Error.prototype;

    #Setting csLog
    csLog.set($scope, "csWizard")

    $scope.loading = true
    $scope.errors = []

    $scope.setOptions = (resource, item, formMode, wizardMaxDepth, parent) ->

      $scope.log("setOptions")
      panelDescriptor = {
        resource : resource
        item : item
