diff --git a/src/Aggregation/AbstractAggregation.php b/src/Aggregation/AbstractAggregation.php
index 8f0ad9c771d23d9f19ee56c41dd0ac50ff3cafcf..975cdaf54c2b5688577e12b518eb39dfae4c5617 100644
--- a/src/Aggregation/AbstractAggregation.php
+++ b/src/Aggregation/AbstractAggregation.php
@@ -11,18 +11,18 @@
 
 namespace ONGR\ElasticsearchDSL\Aggregation;
 
-use ONGR\ElasticsearchDSL\NamedBuilderBag;
-use ONGR\ElasticsearchDSL\NamedBuilderInterface;
+use ONGR\ElasticsearchDSL\BuilderBag;
+use ONGR\ElasticsearchDSL\BuilderInterface;
+use ONGR\ElasticsearchDSL\NameAwareTrait;
 use ONGR\ElasticsearchDSL\ParametersTrait;
 
 /**
  * AbstractAggregation class.
  */
-abstract class AbstractAggregation implements NamedBuilderInterface
+abstract class AbstractAggregation implements BuilderInterface
 {
     use ParametersTrait;
-
-    const PREFIX = 'agg_';
+    use NameAwareTrait;
 
     /**
      * @var string
@@ -30,20 +30,10 @@ abstract class AbstractAggregation implements NamedBuilderInterface
     private $field;
 
     /**
-     * @var string
-     */
-    private $name;
-
-    /**
-     * @var NamedBuilderBag
+     * @var BuilderBag
      */
     private $aggregations;
 
-    /**
-     * @return string
-     */
-    abstract public function getType();
-
     /**
      * Abstract supportsNesting method.
      *
@@ -63,9 +53,7 @@ abstract class AbstractAggregation implements NamedBuilderInterface
      */
     public function __construct($name)
     {
-        $this->name = $name;
-
-        $this->aggregations = new NamedBuilderBag();
+        $this->setName($name);
     }
 
     /**
@@ -84,14 +72,6 @@ abstract class AbstractAggregation implements NamedBuilderInterface
         return $this->field;
     }
 
-    /**
-     * {@inheritdoc}
-     */
-    public function getName()
-    {
-        return self::PREFIX . $this->name;
-    }
-
     /**
      * Adds a sub-aggregation.
      *
@@ -99,17 +79,25 @@ abstract class AbstractAggregation implements NamedBuilderInterface
      */
     public function addAggregation(AbstractAggregation $abstractAggregation)
     {
+        if (!$this->aggregations) {
+            $this->aggregations = $this->createBuilderBag();
+        }
+
         $this->aggregations->add($abstractAggregation);
     }
 
     /**
      * Returns all sub aggregations.
      *
-     * @return AbstractAggregation[]
+     * @return BuilderBag[]
      */
     public function getAggregations()
     {
-        return $this->aggregations->all();
+        if ($this->aggregations) {
+            return $this->aggregations->all();
+        } else {
+            return [];
+        }
     }
 
     /**
@@ -149,4 +137,14 @@ abstract class AbstractAggregation implements NamedBuilderInterface
 
         return $result;
     }
+
+    /**
+     * Creates BuilderBag new instance.
+     *
+     * @return BuilderBag
+     */
+    private function createBuilderBag()
+    {
+        return new BuilderBag();
+    }
 }
diff --git a/src/NamedBuilderBag.php b/src/BuilderBag.php
similarity index 60%
rename from src/NamedBuilderBag.php
rename to src/BuilderBag.php
index d1a22684a9013f6c2d0a48248453f64cc8e718c4..4894764905646915fa51f545818bd1a9c4ba47d7 100644
--- a/src/NamedBuilderBag.php
+++ b/src/BuilderBag.php
@@ -14,27 +14,17 @@ namespace ONGR\ElasticsearchDSL;
 /**
  * Container for named builders.
  */
-class NamedBuilderBag
+class BuilderBag
 {
     /**
-     * @var NamedBuilderInterface[]
+     * @var BuilderInterface[]
      */
     private $bag = [];
 
     /**
-     * @param NamedBuilderInterface[] $builders
+     * @param BuilderInterface[] $builders
      */
-    public function __construct(array $builders = [])
-    {
-        $this->set($builders);
-    }
-
-    /**
-     * Replaces builders with new ones.
-     *
-     * @param NamedBuilderInterface[] $builders
-     */
-    public function set(array $builders)
+    public function __construct($builders = [])
     {
         foreach ($builders as $builder) {
             $this->add($builder);
@@ -44,15 +34,25 @@ class NamedBuilderBag
     /**
      * Adds a builder.
      *
-     * @param NamedBuilderInterface $builder
+     * @param BuilderInterface $builder
+     *
+     * @return string
      */
-    public function add(NamedBuilderInterface $builder)
+    public function add(BuilderInterface $builder)
     {
-        $this->bag[$builder->getName()] = $builder;
+        if (method_exists($builder, 'getName')) {
+            $name = $builder->getName();
+        } else {
+            $name = uniqid();
+        }
+
+        $this->bag[$name] = $builder;
+
+        return $name;
     }
 
     /**
-     * Checks if builder is set by name.
+     * Checks if builder exists by a specific name.
      *
      * @param string $name Builder name.
      *
@@ -66,7 +66,7 @@ class NamedBuilderBag
     /**
      * Removes a builder by name.
      *
-     * @param string $name Builder name.
+     * @param string $name builder name.
      */
     public function remove($name)
     {
@@ -84,9 +84,9 @@ class NamedBuilderBag
     /**
      * Returns a builder by name.
      *
-     * @param string $name Builder name.
+     * @param string $name builder name.
      *
-     * @return NamedBuilderInterface
+     * @return BuilderInterface
      */
     public function get($name)
     {
@@ -96,16 +96,16 @@ class NamedBuilderBag
     /**
      * Returns all builders contained.
      *
-     * @param string|null $type Builder type.
+     * @param string|null $type builder type.
      *
-     * @return NamedBuilderInterface[]
+     * @return BuilderInterface[]
      */
     public function all($type = null)
     {
         return array_filter(
             $this->bag,
-            /** @var NamedBuilderInterface $builder */
-            function (NamedBuilderInterface $builder) use ($type) {
+            /** @var BuilderInterface $builder */
+            function (BuilderInterface $builder) use ($type) {
                 return $type === null || $builder->getType() == $type;
             }
         );
@@ -116,11 +116,10 @@ class NamedBuilderBag
      */
     public function toArray()
     {
-        $out = [];
+        $output = [];
         foreach ($this->all() as $builder) {
-            $out = array_merge($out, $builder->toArray());
+            $output = array_merge($output, $builder->toArray());
         }
-
-        return $out;
+        return $output;
     }
 }