     p = parseLevel(level)
     if p.minor
         return p.major
-    else 
+    else
         return Table.main
-        
-        
+
+
 tablesSchema.methods.addTable = (id) ->
+    if id in @tables
+        return
     @update({$push: { tables: id }})
 
 tablesSchema.methods.setOrder = (order) ->

        for problem in @problems
            result.push(problem)
        result
            
            
tablesSchema.statics.findAll = ->
    @find {}
            
tablesSchema.statics.removeDuplicateChildren = () ->
        tables = await Table.findAll()
        for table in tables

        await p.addTable(@_id)
        if p.order > @order - 1
            await p.setOrder(@order - 1)

tablesSchema.methods.height = () ->
        if @tables.length > 0
            return await (await Table.findById(@tables[0])).height() + 1
        else
            return 1

tablesSchema.methods.expand = () ->
        expandedTables = []
        for table in @tables
