Index: library/bdm/estim/kalman.h
===================================================================
--- library/bdm/estim/kalman.h (revision 660)
+++ library/bdm/estim/kalman.h (revision 675)
@@ -214,5 +214,5 @@
 		*/
 		void bayes (const vec &dt);
-		
+
 		void from_setting(const Setting &set){
 			Kalman<chmat>::from_setting(set);
Index: library/bdm/estim/particles.h
===================================================================
--- library/bdm/estim/particles.h (revision 665)
+++ library/bdm/estim/particles.h (revision 675)
@@ -389,5 +389,5 @@
 		}
 	}
-	
+
 };
 UIREGISTER(MPF);
Index: library/bdm/base/bdmbase.h
===================================================================
--- library/bdm/base/bdmbase.h (revision 665)
+++ library/bdm/base/bdmbase.h (revision 675)
@@ -326,9 +326,109 @@
 };
 
-class mpdf;
+class epdf;
+
+//! Conditional probability density, e.g. modeling \f$ f( x | y) \f$, where \f$ x \f$ is random variable, \c rv, and \f$ y \f$ is conditioning variable, \c rvc.
+class mpdf : public root {
+protected:
+	//!dimension of the condition
+	int dimc;
+	//! random variable in condition
+	RV rvc;
+
+	//! TODO
+	int dim;
+
+	//! TODO
+	RV rv;
+
+public:
+	//! \name Constructors
+	//! @{
+
+	mpdf() : dimc ( 0 ), rvc(), dim(0), rv() { }
+
+	mpdf ( const mpdf &m ) : dimc ( m.dimc ), rvc ( m.rvc ), rv( m.rv ), dim( m.dim) { }
+	//!@}
+
+	//! \name Matematical operations
+	//!@{
+
+	//! Returns a sample from the density conditioned on \c cond, \f$x \sim epdf(rv|cond)\f$. \param cond is numeric value of \c rv
+	virtual vec samplecond ( const vec &cond ) {
+		bdm_error ( "Not implemented" );
+		return vec();
+	}
+
+	//! Returns \param N samples from the density conditioned on \c cond, \f$x \sim epdf(rv|cond)\f$. \param cond is numeric value of \c rv
+	virtual mat samplecond_m ( const vec &cond, int N );
+
+	//! Shortcut for conditioning and evaluation of the internal epdf. In some cases,  this operation can be implemented efficiently.
+	virtual double evallogcond ( const vec &dt, const vec &cond ) {
+		bdm_error ( "Not implemented" );
+		return 0.0;
+	}
+
+	//! Matrix version of evallogcond
+	virtual vec evallogcond_m ( const mat &Dt, const vec &cond ) {
+		vec v ( Dt.cols() );
+		for ( int i = 0; i < Dt.cols(); i++ ) {
+			v ( i ) = evallogcond ( Dt.get_col ( i ), cond );
+		}
+		return v;
+	}
+
+	//! Array<vec> version of evallogcond
+	virtual vec evallogcond_m ( const Array<vec> &Dt, const vec &cond ) {
+		bdm_error ( "Not implemented" );
+		return vec();
+	}
+
+	//! \name Access to attributes
+	//! @{
+
+	const RV& _rv() const {
+		return rv;
+	}
+	const RV& _rvc() const {
+		return rvc;
+	}
+
+	int dimension() const {
+		return dim;
+	}
+	int dimensionc() {
+		return dimc;
+	}
+
+	//! Load from structure with elements:
+	//!  \code
+	//! { class = "mpdf_offspring",
+	//!   rv = {class="RV", names=(...),}; // RV describing meaning of random variable
+	//!   rvc= {class="RV", names=(...),}; // RV describing meaning of random variable in condition
+	//!   // elements of offsprings
+	//! }
+	//! \endcode
+	//!@}
+	void from_setting ( const Setting &set );
+	//!@}
+
+	//! \name Connection to other objects
+	//!@{
+	void set_rvc ( const RV &rvc0 ) {
+		rvc = rvc0;
+	}
+	void set_rv ( const RV &rv0 ) {
+		rv = rv0;
+	}
+
+	bool isnamed() {
+		return ( dim == rv._dsize() ) && ( dimc == rvc._dsize() );
+	}
+	//!@}
+};
+SHAREDPTR ( mpdf );
 
 //! Probability density function with numerical statistics, e.g. posterior density.
-
-class epdf : public root {
+class epdf : public mpdf {
 protected:
 	//! dimension of the random variable
@@ -456,113 +556,20 @@
 	}
 
+
+/*! \brief Unconditional mpdf, allows using epdf in the role of mpdf.
+
+*/
+
+
+/// MEPDF BEGINS HERE TODO
+	//! empty
+	vec samplecond ( const vec &cond ) {
+		return sample();
+	}
+	double evallogcond ( const vec &val, const vec &cond ) {
+		return evallog ( val );
+	}
 };
 SHAREDPTR ( epdf );
-
-//! Conditional probability density, e.g. modeling \f$ f( x | y) \f$, where \f$ x \f$ is random variable, \c rv, and \f$ y \f$ is conditioning variable, \c rvc.
-class mpdf : public root {
-protected:
-	//!dimension of the condition
-	int dimc;
-	//! random variable in condition
-	RV rvc;
-private:
-	//! internal epdf, used only as cache to avoid virtual calls of \c _rv() and \c _dimension()
-	epdf* ep;
-
-protected:
-	//! set internal pointer \c ep to point to given \c iepdf
-	void set_ep ( epdf &iepdf ) {
-		ep = &iepdf;
-	}
-	//! set internal pointer \c ep to point to given \c iepdf
-	void set_ep ( epdf *iepdfp ) {
-		ep = iepdfp;
-	}
-
-public:
-	//! \name Constructors
-	//! @{
-
-	mpdf() : dimc ( 0 ), rvc(), ep ( NULL ) { }
-
-	mpdf ( const mpdf &m ) : dimc ( m.dimc ), rvc ( m.rvc ), ep ( m.ep ) { }
-	//!@}
-
-	//! \name Matematical operations
-	//!@{
-
-	//! Returns a sample from the density conditioned on \c cond, \f$x \sim epdf(rv|cond)\f$. \param cond is numeric value of \c rv
-	virtual vec samplecond ( const vec &cond ) {
-		bdm_error ( "Not implemented" );
-		return vec();
-	}
-
-	//! Returns \param N samples from the density conditioned on \c cond, \f$x \sim epdf(rv|cond)\f$. \param cond is numeric value of \c rv
-	virtual mat samplecond_m ( const vec &cond, int N );
-
-	//! Shortcut for conditioning and evaluation of the internal epdf. In some cases,  this operation can be implemented efficiently.
-	virtual double evallogcond ( const vec &dt, const vec &cond ) {
-		bdm_error ( "Not implemented" );
-		return 0.0;
-	}
-
-	//! Matrix version of evallogcond
-	virtual vec evallogcond_m ( const mat &Dt, const vec &cond ) {
-		vec v ( Dt.cols() );
-		for ( int i = 0; i < Dt.cols(); i++ ) {
-			v ( i ) = evallogcond ( Dt.get_col ( i ), cond );
-		}
-		return v;
-	}
-
-	//! Array<vec> version of evallogcond
-	virtual vec evallogcond_m ( const Array<vec> &Dt, const vec &cond ) {
-		bdm_error ( "Not implemented" );
-		return vec();
-	}
-
-	//! \name Access to attributes
-	//! @{
-
-	const RV& _rv() const {
-		return ep->_rv();
-	}
-	const RV& _rvc() const {
-		return rvc;
-	}
-
-	int dimension() const {
-		return ep->dimension();
-	}
-	int dimensionc() {
-		return dimc;
-	}
-
-	//! Load from structure with elements:
-	//!  \code
-	//! { class = "mpdf_offspring",
-	//!   rv = {class="RV", names=(...),}; // RV describing meaning of random variable
-	//!   rvc= {class="RV", names=(...),}; // RV describing meaning of random variable in condition
-	//!   // elements of offsprings
-	//! }
-	//! \endcode
-	//!@}
-	void from_setting ( const Setting &set );
-	//!@}
-
-	//! \name Connection to other objects
-	//!@{
-	void set_rvc ( const RV &rvc0 ) {
-		rvc = rvc0;
-	}
-	void set_rv ( const RV &rv0 ) {
-		ep->set_rv ( rv0 );
-	}
-	bool isnamed() {
-		return ( ep->isnamed() ) && ( dimc == rvc._dsize() );
-	}
-	//!@}
-};
-SHAREDPTR ( mpdf );
 
 //! Mpdf with internal epdf that is modified by function \c condition
@@ -575,5 +582,5 @@
 	//! constructor
 	mpdf_internal() : mpdf(), iepdf() {
-		set_ep ( iepdf );
+//		set_ep ( iepdf ); TODO!
 	}
 
@@ -906,39 +913,4 @@
 };
 
-/*! \brief Unconditional mpdf, allows using epdf in the role of mpdf.
-
-*/
-class mepdf : public mpdf {
-	//! Internal shared pointer to epdf
-	shared_ptr<epdf> iepdf;
-public:
-	//!Default constructor
-	mepdf() { }
-	//! Set internal shared pointer
-	mepdf ( shared_ptr<epdf> em ) {
-		iepdf = em;
-		set_ep ( *iepdf.get() );
-		dimc = 0;
-	}
-
-	//! empty
-	vec samplecond ( const vec &cond ) {
-		return iepdf->sample();
-	}
-	double evallogcond ( const vec &val, const vec &cond ) {
-		return iepdf->evallog ( val );
-	}
-
-	//! Load from structure with elements:
-	//!  \code
-	//! { class = "mepdf",
-	//!   epdf = {class="epdf_offspring",...}
-	//! }
-	//! \endcode
-	//!@}
-	void from_setting ( const Setting &set );
-};
-UIREGISTER ( mepdf );
-SHAREDPTR ( mepdf );
 
 //! \brief Combines RVs from a list of mpdfs to a single one.
@@ -1209,5 +1181,4 @@
 		if ( LFlags ( 3 ) ) LIDs ( 3 ) = L.add ( RV ( "ll", 1 ), name );    //TODO: "local" RV
 	}
-	//! Save results to the given logger, details of what is stored is configured by \c LIDs and \c options
 	virtual void logit ( logger &L ) {
 		L.logit ( LIDs ( 0 ), posterior().mean() );
Index: library/bdm/base/bdmbase.cpp
===================================================================
--- library/bdm/base/bdmbase.cpp (revision 624)
+++ library/bdm/base/bdmbase.cpp (revision 675)
@@ -373,10 +373,4 @@
 }
 
-void mepdf::from_setting ( const Setting &set ) {
-	shared_ptr<epdf> e ( UI::build<epdf> ( set, "epdf", UI::compulsory ) );
-	iepdf = e;
-	set_ep ( iepdf.get() );
-}
-
 RV get_composite_rv ( const Array<shared_ptr<mpdf> > &mpdfs,
                       bool checkoverlap ) {
Index: library/bdm/stat/emix.cpp
===================================================================
--- library/bdm/stat/emix.cpp (revision 620)
+++ library/bdm/stat/emix.cpp (revision 675)
@@ -207,8 +207,6 @@
 	dls.set_size ( mFacs.length() );
 
-	set_ep ( iepdf);
-	RV rv = get_composite_rv ( mpdfs, true );
-	set_rv ( rv );
-	iepdf.set_parameters ( rv._dsize() );
+	rv = get_composite_rv ( mpdfs, true );
+	dim = rv._dsize();
 
 	for ( int i = 0; i < mpdfs.length(); i++ ) {
Index: library/bdm/stat/emix.h
===================================================================
--- library/bdm/stat/emix.h (revision 660)
+++ library/bdm/stat/emix.h (revision 675)
@@ -47,17 +47,16 @@
 	//!datalink between conditional and nom
 	datalink_m2e dl;
-	//! dummy epdf that stores only rv and dim
-	epdf iepdf;
 public:
 	//!Default constructor. By default, the given epdf is not copied!
 	//! It is assumed that this function will be used only temporarily.
-	mratio ( const epdf* nom0, const RV &rv, bool copy = false ) : mpdf ( ), dl ( ),iepdf() {
+	mratio ( const epdf* nom0, const RV &rv, bool copy = false ) : mpdf ( ), dl ( ) {
 		// adjust rv and rvc
+
+		set_rv( rv ); // TODO co kdyby tohle samo uz nastavovalo dimension?!?!
+		dim = rv._dsize();
+
 		rvc = nom0->_rv().subt ( rv );
 		dimc = rvc._dsize();
-		set_ep ( iepdf );
-		iepdf.set_parameters ( rv._dsize() );
-		iepdf.set_rv ( rv );
-
+	
 		//prepare data structures
 		if ( copy ) {
@@ -74,4 +73,5 @@
 		dl.set_connection ( rv, rvc, nom0->_rv() );
 	};
+
 	double evallogcond ( const vec &val, const vec &cond ) {
 		double tmp;
@@ -469,9 +469,7 @@
 	//!weights of the components
 	vec w;
-	//! dummy epdfs
-	epdf dummy_epdf;
 public:
 	//!Default constructor
-	mmix() : Coms(0), dummy_epdf() { set_ep(dummy_epdf);	}
+	mmix() : Coms(0) { }
 
 	//! Set weights \c w and components \c R
@@ -483,5 +481,5 @@
 		if (Coms0.length()>0){
 			set_rv(Coms(0)->_rv());
-			dummy_epdf.set_parameters(Coms(0)->_rv()._dsize());
+			dim = rv._dsize();
 			set_rvc(Coms(0)->_rvc());
 			dimc = rvc._dsize();
Index: library/tests/merger_2d_test.cpp
===================================================================
--- library/tests/merger_2d_test.cpp (revision 529)
+++ library/tests/merger_2d_test.cpp (revision 675)
@@ -32,8 +32,6 @@
 
 	mpdf_array A ( 2 );
-	mepdf_ptr A1 = new mepdf ( f1 );
-	mepdf_ptr A2 = new mepdf ( f2 );
-	A ( 0 ) = A1;
-	A ( 1 ) = A2;
+	A ( 0 ) = f1;
+	A ( 1 ) = f2;
 
 	int Npoints = 100;
Index: library/tests/mepdf.cfg
===================================================================
--- library/tests/mepdf.cfg (revision 489)
+++ library/tests/mepdf.cfg (revision 675)
@@ -3,6 +3,4 @@
   class = "mpdf_harness";
   mpdf = {
-    class = "mepdf";
-    epdf = {
       class = "enorm<ldmat>";
       mu = [ 1.1, -1.0 ];
@@ -13,5 +11,4 @@
 	names = ( "x", "y" );
       };
-    };
   };
   cond = [ 1.5, 1.7 ];
Index: library/tests/mpdf_test.cpp
===================================================================
--- library/tests/mpdf_test.cpp (revision 529)
+++ library/tests/mpdf_test.cpp (revision 675)
@@ -54,6 +54,5 @@
 
 	eN->set_mu ( vec_2 ( 0.0, 0.0 ) );
-	mepdf_ptr mEnorm = new mepdf ( eN );
-	mComs ( 1 ) = mEnorm;
+	mComs ( 1 ) = eN;
 
 	mMix.set_parameters ( vec_2 ( 0.5, 0.5 ), mComs );
@@ -87,6 +86,5 @@
 
 	eMix->set_parameters ( vec_2 ( 0.5, 0.5 ), Coms );
-	mepdf meMix ( eMix );
-	check_mean ( meMix, mu0, N, eMix->mean(), 0.1 );
+	check_mean ( *eMix, mu0, N, eMix->mean(), 0.1 );
 }
 
Index: library/tests/mprod.cfg
===================================================================
--- library/tests/mprod.cfg (revision 531)
+++ library/tests/mprod.cfg (revision 675)
@@ -21,7 +21,4 @@
     }, 
     {
-      class = "mepdf";
-      epdf : 
-      {
 	class = "egamma";
 	alpha = 2.0;
@@ -32,5 +29,4 @@
 	  names = ( "a" );
 	};
-      };
     });
   };
@@ -46,7 +42,4 @@
     mpdfs = ( 
     {
-      class = "mepdf";
-      epdf : 
-      {
 	class = "enorm<ldmat>";
 	mu = [ 1.5, 1.7 ];
@@ -58,10 +51,6 @@
 	  sizes = [ 2 ];
 	};
-      };
     }, 
     {
-      class = "mepdf";
-      epdf : 
-      {
 	class = "egamma";
 	alpha = [ 100000, 10000 ];
@@ -72,5 +61,4 @@
 	  sizes = [ 2 ];
 	};
-      };
     });
   };
Index: library/tests/merger_test.cpp
===================================================================
--- library/tests/merger_test.cpp (revision 562)
+++ library/tests/merger_test.cpp (revision 675)
@@ -22,6 +22,6 @@
 
 	mpdf_array A ( 2 );
-	A ( 0 ) = new mepdf ( f1 );
-	A ( 1 ) = new mepdf ( f2 );
+	A ( 0 ) = f1;
+	A ( 1 ) = f2;
 
 	int Npoints = 100;
Index: library/tests/merger.cfg
===================================================================
--- library/tests/merger.cfg (revision 562)
+++ library/tests/merger.cfg (revision 675)
@@ -1,7 +1,4 @@
 Sources = ( 
   {
-    class = "mepdf";
-    epdf : 
-    {
       class = "enorm<ldmat>";
       mu = ( "matrix", 1, 2, [ 0.0, 2.0 ] );
@@ -12,10 +9,6 @@
 	names = ( "a", "b" );
       };
-    };
   }, 
   {
-    class = "mepdf";
-    epdf : 
-    {
       class = "egiw";
       V = ( "matrix", 2, 2, [ 20.0, 8.0, 8.0, 4.0 ] );
@@ -27,5 +20,4 @@
 	names = ( "a", "b" );
       };
-    };
   } );
 Support : 
Index: library/tests/epdf_harness.cpp
===================================================================
--- library/tests/epdf_harness.cpp (revision 598)
+++ library/tests/epdf_harness.cpp (revision 675)
@@ -71,5 +71,5 @@
 		mpdf_array aa ( 2 );
 		aa ( 0 ) = c;
-		aa ( 1 ) = new mepdf ( m );
+		aa ( 1 ) = m;
 		mprod mEp ( aa );
 
Index: library/tests/merger_iter_test.cpp
===================================================================
--- library/tests/merger_iter_test.cpp (revision 529)
+++ library/tests/merger_iter_test.cpp (revision 675)
@@ -33,7 +33,7 @@
 
 	mpdf_array A ( 3 );
-	A ( 0 ) = new mepdf ( f1 );
-	A ( 1 ) = new mepdf ( f2 );
-	A ( 2 ) = new mepdf ( f3 );
+	A ( 0 ) = f1;
+	A ( 1 ) = f2;
+	A ( 2 ) = f3;
 
 	int Npoints = 100;
Index: library/tests/merger_error.cfg
===================================================================
--- library/tests/merger_error.cfg (revision 562)
+++ library/tests/merger_error.cfg (revision 675)
@@ -1,7 +1,4 @@
 Sources = ( 
   {
-    class = "mepdf";
-    epdf : 
-    {
       class = "enorm<ldmat>";
       mu = ( "matrix", 1, 2, [ 0.0, 2.0 ] );
@@ -12,10 +9,6 @@
 	names = ( "a", "b" );
       };
-    };
   }, 
   {
-    class = "mepdf";
-    epdf : 
-    {
       class = "egiw";
       V = ( "matrix", 2, 2, [ 20.0, 8.0, 8.0, 4.0 ] );
@@ -27,5 +20,4 @@
 	names = ( "a", "b" );
       };
-    };
   } );
 Support : 
