diff --git a/CMakeLists.txt b/CMakeLists.txt
index ec5ecbac404223736dd23199011bcc609ed95767..b263a8adf9c04a228ae9fc566fe0bd9913f5e2a8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -85,6 +85,13 @@ if(DEFINED EIS_FOUND)
 	endif(DEFINED TORCH_LIBRARIES)
 endif(DEFINED EIS_FOUND)
 
+if(DEFINED PKGCONFIG_FOUND)
+	configure_file(pkgconfig/libeisdrt_torch.pc.in pkgconfig/libeisdrt_torch.pc @ONLY)
+	configure_file(pkgconfig/libeisdrt.pc.in pkgconfig/libeisdrt.pc @ONLY)
+	install(FILES ${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/libeisdrt_torch.pc DESTINATION lib/pkgconfig)
+	install(FILES ${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/libeisdrt.pc DESTINATION lib/pkgconfig)
+endif(DEFINED PKGCONFIG_FOUND)
+
 set(API_HEADERS_DIR eisdrt/)
 set(API_HEADERS
 	${API_HEADERS_DIR}/eigendrt.h
diff --git a/drt.cpp b/drt.cpp
index a5f6e1a948a3470e42f3ff2b05fbdd4a0a232d91..6812217f7a3c90fc49d849485179f889d2377db9 100644
--- a/drt.cpp
+++ b/drt.cpp
@@ -19,6 +19,8 @@
 //
 
 #include "eisdrt/eigendrt.h"
+#include "eisdrt/types.h"
+#include <stdexcept>
 
 #ifdef USE_EISGEN
 #include "eisdrt/eisdrt.h"
@@ -117,17 +119,11 @@ public:
 		int64_t size = x.size();
 		Eigen::Vector<fv, Eigen::Dynamic> xLeft = x.head(x.size()-1);
 
-		std::cout<<"aMatrixReal:\n"<<aMatrixReal<<"\nxLeft:\n"<<xLeft<<"\nx:\n"<<x<<std::endl;
 		Eigen::Vector<fv, Eigen::Dynamic> t = aMatrixReal*xLeft;
-		std::cout<<"T1:\n"<<t<<std::endl;
 		t = t - impedanceSpectra.real();
-		std::cout<<"T2:\n"<<t<<std::endl;
 		t = t.array() + x[size-1];
-		std::cout<<"T3:\n"<<t<<std::endl;
 		t = t.array().pow(2);
-		std::cout<<"T4:\n"<<t<<std::endl;
 		fv MSE_re = t.sum();
-		std::cout<<"T5:\n"<<MSE_re<<std::endl;
 
 		t = (aMatrixImag*xLeft - impedanceSpectra.imag()).array().pow(2);
 		fv MSE_im = t.sum();
@@ -155,7 +151,6 @@ public:
 	fv operator()(Eigen::VectorX<fv>& x, Eigen::VectorX<fv>& grad)
 	{
 		grad = getGrad(std::bind(&RtFunct::function, this, std::placeholders::_1), x, epsilon);
-		std::cout<<"grad:\n"<<grad<<std::endl;
 		return function(x);
 	}
 };
@@ -187,14 +182,24 @@ Eigen::VectorX<fv> calcDrt(Eigen::VectorX<std::complex<fv>>& impedanceSpectra, E
 	RtFunct<fv> funct(impedanceSpectra, aMatrixImag, aMatrixReal, 0.01, fp.step);
 
 	Eigen::VectorX<fv> x = guesStartingPoint(omegaTensor, impedanceSpectra);
-	std::cout<<"StartingPoint\n"<<x<<std::endl;
 	Eigen::Matrix<fv, Eigen::Dynamic, 2> bounds = calcBounds(impedanceSpectra, x);
 	Eigen::VectorX<fv> lowerBounds = bounds.col(0);
 	Eigen::VectorX<fv> upperBounds = bounds.col(1);
 
 	fv fx;
-	fm.iterations = solver.minimize(funct, x, fx, lowerBounds, upperBounds);
-	fm.fx = fx;
+	try
+	{
+		fm.iterations = solver.minimize(funct, x, fx, lowerBounds, upperBounds);
+		fm.fx = fx;
+	}
+	catch(const std::invalid_argument& ex)
+	{
+		throw drt_errror(std::string(ex.what()));
+	}
+	catch(const std::runtime_error& ex)
+	{
+		throw drt_errror(std::string(ex.what()));
+	}
 
 	return x;
 }
diff --git a/eisdrt/types.h b/eisdrt/types.h
index 1d3c0286f115958b20dcce7ced75aaf59f4d3885..4427b3e77c2005e2925c4236602be8b9685f13fa 100644
--- a/eisdrt/types.h
+++ b/eisdrt/types.h
@@ -18,6 +18,8 @@
  */
 
 #pragma once
+#include <exception>
+#include <string>
 
 /**
 Types for use with all eisdrt apis
@@ -26,6 +28,22 @@ Types for use with all eisdrt apis
 * @{
 */
 
+
+/**
+ * @brief Exception thrown if drt could not be calcualted
+ */
+class drt_errror: public std::exception
+{
+	std::string whatStr;
+public:
+	drt_errror(const std::string& whatIn): whatStr(whatIn)
+	{}
+	virtual const char* what() const noexcept override
+	{
+		return whatStr.c_str();
+	}
+};
+
 /**
  * @brief Returned information on a fit
  */