diff --git a/alib2/src/regexp/Alternation.cpp b/alib2/src/regexp/Alternation.cpp
index 8f5c6618e7e68d50e18c5080c7d5eea9740b108f..d12fce3d4cf23d9f482e59bb6931873b7ba7a844 100644
--- a/alib2/src/regexp/Alternation.cpp
+++ b/alib2/src/regexp/Alternation.cpp
@@ -16,7 +16,7 @@ Alternation::Alternation() {
 
 Alternation::Alternation(const Alternation& other) {
 	for (const auto& element : other.elements) {
-		elements.insert(std::shared_ptr<RegExpElement>(element->clone()));
+		elements.insert(element->clone());
 	}
 }
 
@@ -41,19 +41,22 @@ Alternation& Alternation::operator=(Alternation&& other) noexcept {
 }
 
 Alternation::~Alternation() noexcept {
+	for (auto element : elements) {
+		delete element;
+	}
 	elements.clear();
 }
 
-const std::set<std::shared_ptr<const RegExpElement>, std::owner_less<std::shared_ptr<const RegExpElement> > > & Alternation::getElements() const {
-	return * reinterpret_cast<const std::set<std::shared_ptr<const RegExpElement>, std::owner_less<std::shared_ptr<const RegExpElement> > > * > (&elements);
+const std::set<const RegExpElement*, RegExpElement::PointerLess > & Alternation::getElements() const {
+	return * reinterpret_cast<const std::set<const RegExpElement*, RegExpElement::PointerLess > * > (&elements);
 }
 
 void Alternation::insertElement(const RegExpElement& element) {
-	this->elements.insert(std::shared_ptr<RegExpElement>(element.clone()));
+	this->elements.insert(element.clone());
 }
 
 void Alternation::insertElement(RegExpElement&& element) {
-	this->elements.insert(std::shared_ptr<RegExpElement>(std::move(element).plunder()));
+	this->elements.insert(std::move(element).plunder());
 }
 
 RegExpElement* Alternation::clone() const {
diff --git a/alib2/src/regexp/Alternation.h b/alib2/src/regexp/Alternation.h
index d5fc72c94b3770af690af9286a23638751dc9b83..75c9b1c5eba6dbbd0e378823e38e244b2ba2d2c6 100644
--- a/alib2/src/regexp/Alternation.h
+++ b/alib2/src/regexp/Alternation.h
@@ -9,7 +9,6 @@
 #define ALTERNATION_H_
 
 #include <set>
-#include <memory>
 #include "RegExpElement.h"
 
 namespace regexp {
@@ -27,7 +26,7 @@ protected:
 	
 	virtual RegExpElement* plunder() &&;
 
-	std::set<std::shared_ptr<RegExpElement>, std::owner_less<std::shared_ptr<RegExpElement> > > elements;
+	std::set<RegExpElement*, RegExpElement::PointerLess > elements;
 public:
 	Alternation();
 	Alternation(const Alternation& other);
@@ -39,7 +38,7 @@ public:
 	/**
 	 * @return elements
 	 */
-	const std::set<std::shared_ptr<const RegExpElement>, std::owner_less<std::shared_ptr<const RegExpElement> > > & getElements() const;
+	const std::set<const RegExpElement*, RegExpElement::PointerLess > & getElements() const;
 
 	/**
 	 * @param element to insert
diff --git a/alib2/src/regexp/Concatenation.cpp b/alib2/src/regexp/Concatenation.cpp
index baff26388374d73693b45086abcb34dd3ee2c596..c658061daa81c0f8371ac354640c60473c8c7e81 100644
--- a/alib2/src/regexp/Concatenation.cpp
+++ b/alib2/src/regexp/Concatenation.cpp
@@ -15,7 +15,7 @@ Concatenation::Concatenation() {
 
 Concatenation::Concatenation(const Concatenation& other) {
 	for (auto element : other.elements) {
-		elements.push_back(std::shared_ptr<RegExpElement>(element->clone()));
+		elements.push_back(element->clone());
 	}
 }
 
@@ -40,19 +40,22 @@ Concatenation& Concatenation::operator=(Concatenation&& other) noexcept {
 }
 
 Concatenation::~Concatenation() noexcept {
+	for (auto element : elements) {
+		delete element;
+	}
 	elements.clear();
 }
 
-const std::vector<std::shared_ptr<const RegExpElement> > & Concatenation::getElements() const {
-	return * reinterpret_cast<const std::vector<std::shared_ptr<const RegExpElement> > * > (&elements);
+const std::vector<const RegExpElement*> & Concatenation::getElements() const {
+	return * reinterpret_cast<const std::vector<const RegExpElement*> * > (&elements);
 }
 
 void Concatenation::appendElement(const RegExpElement& element) {
-	this->elements.push_back(std::shared_ptr<RegExpElement>(element.clone()));
+	this->elements.push_back(element.clone());
 }
 
 void Concatenation::appendElement(RegExpElement&& element) {
-	this->elements.push_back(std::shared_ptr<RegExpElement>(std::move(element).plunder()));
+	this->elements.push_back(std::move(element).plunder());
 }
 
 RegExpElement* Concatenation::clone() const {
diff --git a/alib2/src/regexp/Concatenation.h b/alib2/src/regexp/Concatenation.h
index 504e4570e0c4c191eaa9b8977b1a657a663c1e83..3370011c573aa471e364dcfbf9d5be6b26057918 100644
--- a/alib2/src/regexp/Concatenation.h
+++ b/alib2/src/regexp/Concatenation.h
@@ -9,7 +9,6 @@
 #define CONCATENATION_H_
 
 #include <vector>
-#include <memory>
 #include "RegExpElement.h"
 
 namespace regexp {
@@ -27,7 +26,7 @@ protected:
 	
 	virtual RegExpElement* plunder() &&;
 
-	std::vector<std::shared_ptr<RegExpElement> > elements;
+	std::vector<RegExpElement*> elements;
 public:
 	Concatenation();
 	Concatenation(const Concatenation& other);
@@ -39,7 +38,7 @@ public:
 	/**
 	 * @return elements
 	 */
-	const std::vector<std::shared_ptr<const RegExpElement> > & getElements() const;
+	const std::vector<const RegExpElement*> & getElements() const;
 
 	/**
 	 * @param element to append
diff --git a/alib2/src/regexp/Iteration.cpp b/alib2/src/regexp/Iteration.cpp
index 06335296ddb6ed8db913aaf9f761be7c247c137a..b3da1aac9f9ae7825e1a8281419787ef981e3928 100644
--- a/alib2/src/regexp/Iteration.cpp
+++ b/alib2/src/regexp/Iteration.cpp
@@ -11,7 +11,7 @@
 namespace regexp {
 
 Iteration::Iteration() {
-	element = std::shared_ptr<RegExpElement>(new RegExpEmpty());
+	element = new RegExpEmpty();
 }
 
 Iteration::Iteration(const Iteration& other) : element(other.element->clone()) {
@@ -39,19 +39,21 @@ Iteration& Iteration::operator=(Iteration&& other) noexcept {
 }
 
 regexp::Iteration::~Iteration() noexcept {
-
+	delete element;
 }
 
-const std::shared_ptr<const RegExpElement> & Iteration::getElement() const {
-	return * reinterpret_cast<const std::shared_ptr<const RegExpElement> * >  (&element);
+const RegExpElement & Iteration::getElement() const {
+	return *element;
 }
 
 void Iteration::setElement(const RegExpElement& element) {
-	this->element = std::shared_ptr<RegExpElement>(element.clone());
+	delete this->element;
+	this->element = element.clone();
 }
 
 void Iteration::setElement(RegExpElement&& element) {
-	this->element = std::shared_ptr<RegExpElement>(std::move(element).plunder());
+	delete this->element;
+	this->element = std::move(element).plunder();
 }
 
 RegExpElement* Iteration::clone() const {
diff --git a/alib2/src/regexp/Iteration.h b/alib2/src/regexp/Iteration.h
index 8b1d8d5e0e0213226bc11a6c07bcf9caec32f7f6..687fdff80d6892a4d7764052d2b4d601f6109737 100644
--- a/alib2/src/regexp/Iteration.h
+++ b/alib2/src/regexp/Iteration.h
@@ -8,7 +8,6 @@
 #ifndef ITERATION_H_
 #define ITERATION_H_
 
-#include <memory>
 #include "RegExpElement.h"
 #include "RegExpEmpty.h"
 
@@ -20,7 +19,7 @@ namespace regexp {
  */
 class Iteration: public RegExpElement, public std::element<Iteration, RegExpElement::visitor_type> {
 protected:
-	std::shared_ptr<RegExpElement> element;
+	RegExpElement* element;
 
 	/**
 	 * @copydoc RegExpElement::clone() const
@@ -39,7 +38,7 @@ public:
 	/**
 	 * @return element
 	 */
-	const std::shared_ptr<const RegExpElement> & getElement() const;
+	const RegExpElement & getElement() const;
 	
 	/**
 	 * @param element to iterate
diff --git a/alib2/src/regexp/RegExp.cpp b/alib2/src/regexp/RegExp.cpp
index 9435cde0e6da0602456fe427db6b793bf06945c5..7d3e079a4075f6469aff3428f522bd9f3c7d2711 100644
--- a/alib2/src/regexp/RegExp.cpp
+++ b/alib2/src/regexp/RegExp.cpp
@@ -13,11 +13,11 @@
 namespace regexp {
 
 RegExp::RegExp() {
-	this->regExp = std::shared_ptr<RegExpElement>(new RegExpEmpty());
+	this->regExp = new RegExpEmpty();
 }
 
 RegExp::RegExp(const RegExpElement& regExp) {
-	this->regExp = std::shared_ptr<RegExpElement>(regExp.clone());
+	this->regExp = regExp.clone();
 }
 
 RegExp::RegExp(const RegExp& other) : regExp(other.regExp->clone()) {
@@ -45,19 +45,21 @@ RegExp& RegExp::operator=(RegExp&& other) noexcept {
 }
 
 RegExp::~RegExp() noexcept {
-
+	delete regExp;
 }
 
-const std::shared_ptr<const RegExpElement> RegExp::getRegExp() const {
-	return std::shared_ptr<const RegExpElement>(regExp);
+const RegExpElement& RegExp::getRegExp() const {
+	return *regExp;
 }
 
 void RegExp::setRegExp(const RegExpElement& regExp) {
-	this->regExp = std::shared_ptr<RegExpElement>(regExp.clone());
+	delete this->regExp;
+	this->regExp = regExp.clone();
 }
 
 void RegExp::setRegExp(RegExpElement&& regExp) {
-	this->regExp = std::shared_ptr<RegExpElement>(std::move(regExp).plunder());
+	delete this->regExp;
+	this->regExp = std::move(regExp).plunder();
 }
 
 std::set<alphabet::Symbol> RegExp::getAlphabet() const {
diff --git a/alib2/src/regexp/RegExp.h b/alib2/src/regexp/RegExp.h
index 6db74c39f13b1431ba0bf8de522483b7126e6ca7..b0fb4f242e940170e96d344d77137c39926de580 100644
--- a/alib2/src/regexp/RegExp.h
+++ b/alib2/src/regexp/RegExp.h
@@ -11,7 +11,6 @@
 #include <vector>
 #include <list>
 #include <string>
-#include <memory>
 #include "RegExpElement.h"
 #include "RegExpEmpty.h"
 #include "../std/visitor.hpp"
@@ -24,7 +23,7 @@ namespace regexp {
  */
 class RegExp : public std::element<RegExp, std::visitor<RegExp> > {
 protected:
-	std::shared_ptr<RegExpElement> regExp;
+	RegExpElement* regExp;
 
 public:
 	RegExp();
@@ -43,7 +42,7 @@ public:
 	/**
 	 * @return Root node of the regular expression tree
 	 */
-	const std::shared_ptr<const RegExpElement> getRegExp() const;
+	const RegExpElement& getRegExp() const;
 
 	/**
 	 * Sets the root node of the regular expression tree. Doesn't perform copy of the regExp param,
diff --git a/alib2/src/regexp/RegExpElement.h b/alib2/src/regexp/RegExpElement.h
index b08ef261d1823fd67909ae193330cfb202a91749..7fc1beb87a6e7c03b447035895f05ee63ecd9ef1 100644
--- a/alib2/src/regexp/RegExpElement.h
+++ b/alib2/src/regexp/RegExpElement.h
@@ -25,6 +25,13 @@ class RegExpEpsilon;
  * Abstract class representing element in the regular expression. Can be operator or symbol.
  */
 class RegExpElement : virtual public std::elementBase<std::visitor<Alternation, Concatenation, Iteration, RegExpSymbol, RegExpEmpty, RegExpEpsilon> > {
+protected:
+	class PointerLess {
+	public:
+		bool operator()(const RegExpElement* a, const RegExpElement* b) {
+			return *a < *b;
+		}
+	};
 public:
 	/**
 	 * Creates copy of the element.
diff --git a/alib2/src/regexp/RegExpToXMLPrinter.cpp b/alib2/src/regexp/RegExpToXMLPrinter.cpp
index 5d6d2e797e22e984939131b850350a206bba891d..2d5553de8ba4a936183dd6769432d6ae6db505ec 100644
--- a/alib2/src/regexp/RegExpToXMLPrinter.cpp
+++ b/alib2/src/regexp/RegExpToXMLPrinter.cpp
@@ -44,7 +44,7 @@ void RegExpToXMLPrinter::Visit(const Concatenation& concatenation) {
 
 void RegExpToXMLPrinter::Visit(const Iteration& iteration) {
 	m_Out << "<iteration>" << std::endl;
-	const RegExpElement::element_type& object = static_cast<const RegExpElement::element_type&>(*iteration.getElement());
+	const RegExpElement::element_type& object = static_cast<const RegExpElement::element_type&>(iteration.getElement());
 	object.Accept(*this);
 	m_Out << "</iteration>" << std::endl;
 }
@@ -67,7 +67,7 @@ void RegExpToXMLPrinter::Visit(const RegExpEmpty& empty) {
 
 void RegExpToXMLPrinter::Visit(const RegExp& regexp) {
 	m_Out << "<regexp>" << std::endl;
-	regexp.getRegExp()->Accept(*this);
+	regexp.getRegExp().Accept(*this);
 	m_Out << "</regexp>" << std::endl;
 }