 
   # 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) ->

    # A stack template without machines in it? ~ GG
    return callback null  if group.slug is 'koding' or amount is 0

    planConfig   = helpers.getPlanConfig group
    maxAllowed   = MAX_INT

    teamutils.getPlanData planConfig, (err, plan) =>

      return callback err  if err

      maxAllowed = plan.maxInstance  if plan

      JCounter = require '../counter'
      JCounter[change]
        namespace : group.getAt 'slug'
        amount    : amount
        type      : @COUNTER_TYPE.instances
        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


  @updateGroupResourceUsage = (options, callback) ->
