 
   # Just takes the plan config and the stack template content generates rules
   # based on th plan then verifies the content based on the rules generated
-  @validateTemplateContent = (content, planConfig) ->
-
-    rules = teamutils.generateConstraints planConfig
+  @validateTemplateContent = (content, planConfig, callback) ->
 
     try
       template = JSON.parse content
     catch
-      return new KodingError 'Template is not valid'
-
-    { passed, results } = konstraints template, rules, {}
-    return new KodingError results.last[1]  unless passed
-
-    return null
+      callback new KodingError 'Template is not valid'
+
+    teamutils.generateConstraints planConfig, (err, rules) ->
+
+      { passed, results } = konstraints template, rules, {}
+      return new KodingError results.last[1]  unless passed
+
+      return null
 
 
   # Template checker, this will fetch the stack template from given id,


    return callback null  if group.slug is 'koding'

    planConfig   = helpers.getPlanConfig group

    maxAllowed   = MAX_INT
    if planConfig.plan
      plan       = teamutils.getPlanData planConfig
      maxAllowed = plan.member ? MAX_INT

    JCounter = require '../counter'
    JCounter[change]
      namespace : group.getAt 'slug'
      type      : @COUNTER_TYPE.stacks
      max       : maxAllowed
      min       : 0
    , (err) ->
      # no worries about `decrement` errors
      # since 0 is already defined as min ~ GG
      callback if change is 'increment' then err else null


  @updateGroupInstanceUsage = (options, callback) ->

      return callback err  if err
      return callback new KodingError 'Stack template not found'  unless data

      @validateTemplateContent data.template.content, planConfig, callback


  # Takes an array of stack template ids and returns the final result ^^
