old_contents: 'use strict'
  
  var Promise = require('q');
  var _ = require('./lodash')
  
  module.exports = function(service) {
    return function clear(def) {
  
      // Clear a single or multiple column definitions
      if (def) {
        def = _.isArray(def) ? def : [def]
      }
  
      if (!def) {
        // Clear all of the column defenitions
        return Promise.all(_.map(service.columns, disposeColumn))
          .then(function() {
            service.columns = []
            return service
          })
  
      }
  
  
      return Promise.all(_.map(def, function(d) {
          if (_.isObject(d)) {
            d = d.key
          }
          // Clear the column
          var column = _.remove(service.columns, function(c) {
            if (_.isArray(d)) {
              return !_.xor(c.key, d).length
            }
            if (c.key === d) {
              if (c.dynamicReference) {
                return false
              }
              return true
            }
          })[0]
  
          if (!column) {
            // console.info('Attempted to clear a column that is required for another query!', c)
            return
          }
  
          disposeColumn(column)
        }))
        .then(function() {
          return service
        })
  
      function disposeColumn(column) {
        // Dispose the dimension
        var disposalActions = _.map(column.removeListeners, function(listener) {
          return Promise.resolve(listener())
        })
        var filterKey = column.complex ? JSON.stringify(column.key) : column.key
        delete service.filters[filterKey]
        disposalActions.push(Promise.resolve(column.dimension.dispose()))
        return Promise.all(disposalActions)
      }
  
    }
  }
  
new_contents: 'use strict'
  
  var Promise = require('q');
  var _ = require('./lodash')
  
  module.exports = function(service) {
    return function clear(def) {
  
      // Clear a single or multiple column definitions
      if (def) {
        def = _.isArray(def) ? def : [def]
      }
  
      if (!def) {
        // Clear all of the column defenitions
        return Promise.all(_.map(service.columns, disposeColumn))
          .then(function() {
            service.columns = []
            return service
          })
  
      }
  
  
      return Promise.all(_.map(def, function(d) {
          if (_.isObject(d)) {
            d = d.key
          }
          // Clear the column
          var column = _.remove(service.columns, function(c) {
            if (_.isArray(d)) {
              return !_.xor(c.key, d).length
            }
            if (c.key === d) {
              if (c.dynamicReference) {
                return false
              }
              return true
            }
          })[0]
  
          if (!column) {
            // console.info('Attempted to clear a column that is required for another query!', c)
            return
          }
  
          disposeColumn(column)
        }))
        .then(function() {
          return service
        })
  
      function disposeColumn(column) {
        var disposalActions = []
          // Dispose the dimension
        if (column.removeListeners) {
          disposalActions = _.map(column.removeListeners, function(listener) {
            return Promise.resolve(listener())
          })
        }
        var filterKey = column.complex ? JSON.stringify(column.key) : column.key
        delete service.filters[filterKey]
        if(column.dimension){
          disposalActions.push(Promise.resolve(column.dimension.dispose()))
        }
        return Promise.all(disposalActions)
      }
  
    }
  }
  
subject: Clear safety