Index: library/bdm/base/bdmbase.h
===================================================================
--- library/bdm/base/bdmbase.h (revision 737)
+++ library/bdm/base/bdmbase.h (revision 738)
@@ -186,19 +186,6 @@
 	}
 	//! returns name of a scalar at position scalat, i.e. it can be in the middle of vector name, in that case it adds "_%d" to it
-	std::string scalarname ( int scalat ) const {
-		bdm_assert ( scalat < dsize, "Wrong input index" );
-		int id = 0;
-		int scalid = 0;
-		while ( scalid + SIZES ( ids ( id ) ) <= scalat )  {
-			scalid += SIZES ( ids ( id ) );
-			id++;
-		};
-		//now id is the id of variable of interest
-		if ( size ( id ) == 1 )
-			return  NAMES ( ids ( id ) );
-		else
-			return  NAMES ( ids ( id ) ) + "_" + num2str ( scalat - scalid );
-
-	}
+	std::string scalarname ( int scalat ) const;
+
 	void set_time ( int at, int time0 ) {
 		times ( at ) = time0;
@@ -246,14 +233,5 @@
 	}
 	//! return rvs with expanded delayes and sorted in the order of: \f$ [ rv_{0}, rv_{-1},\ldots  rv_{max_delay}]\f$
-	RV expand_delayes() const {
-		RV rvt = this->remove_time(); //rv at t=0
-		RV tmp = rvt;
-		int td = mint();
-		for ( int i = -1; i >= td; i-- ) {
-			rvt.t_plus ( -1 );
-			tmp.add ( rvt ); //shift u1
-		}
-		return tmp;
-	}
+	RV expand_delayes() const;
 	//!@}
 
@@ -336,27 +314,7 @@
 	//! returns an identifier which will be later needed for calling the \c logit() function
 	//! For empty RV it returns -1, this entry will be ignored by \c logit().
-	virtual int add_vector ( const RV &rv, string prefix = "" ) {
-		int id;
-		if ( rv._dsize() > 0 ) {
-			id = entries.length();
-			names = concat ( names, prefix ); // diff
-			entries.set_length ( id + 1, true );
-			entries ( id ) = rv;
-		} else {
-			id = -1;
-		}
-		return id; // identifier of the last entry
-	}
-	virtual int add_setting ( const string &prefix ) {
-		Setting &root = setting_conf.getRoot();
-		int id = root.getLength(); //root must be group!!
-		if ( prefix.length() > 0 ) {
-			settings.set_length ( id + 1, true );
-			settings ( id ) = &root.add ( prefix, Setting::TypeList );
-		} else {
-			id = -1;
-		}
-		return id;
-	}
+	virtual int add_vector ( const RV &rv, string prefix = "" );
+
+	virtual int add_setting ( const string &prefix );
 
 	//! log this vector
@@ -622,45 +580,7 @@
 	//!  #1 mean
 	//!  #2 mean + lower & upper bound
-	void log_register ( logger &L, const string &prefix ) {
-		RV r;
-		if ( isnamed() ) {
-			r = _rv();
-		} else {
-			r = RV ( "", dimension() );
-		};
-		root::log_register ( L, prefix );
-
-		// log full data
-		if ( log_level == 10 ) {
-			logrec->ids.set_size ( 1 );
-			logrec->ids ( 0 ) = logrec->L.add_setting ( prefix );
-		} else {
-			// log only
-			logrec->ids.set_size ( 3 );
-			if ( log_level > 0 ) {
-				logrec->ids ( 0 ) = logrec->L.add_vector ( r, prefix + logrec->L.prefix_sep() + "mean" );
-			}
-			if ( log_level > 1 ) {
-				logrec->ids ( 1 ) = logrec->L.add_vector ( r, prefix + logrec->L.prefix_sep() + "lb" );
-				logrec->ids ( 2 ) = logrec->L.add_vector ( r, prefix + logrec->L.prefix_sep() + "ub" );
-			}
-		}
-	}
-	void log_write() const {
-		if ( log_level == 10 ) {
-			to_setting ( logrec->L.log_to_setting ( logrec->ids ( 0 ) ) );
-		} else {
-			if ( log_level > 0 ) {
-				logrec->L.log_vector ( logrec->ids ( 0 ), mean() );
-			}
-			if ( log_level > 1 ) {
-				vec lb;
-				vec ub;
-				qbounds ( lb, ub );
-				logrec->L.log_vector ( logrec->ids ( 1 ), lb );
-				logrec->L.log_vector ( logrec->ids ( 2 ), ub );
-			}
-		}
-	}
+	void log_register ( logger &L, const string &prefix );
+
+	void log_write() const;
 	//!@}
 
@@ -868,36 +788,8 @@
 	}
 
-	void set_connection ( const RV &rv, const RV &rv_up ) {
-		// create link between up and down
-		datalink_part::set_connection ( rv, rv_up.remove_time() ); // only non-delayed version
-
-		// create rvs of history
-		// we can store only what we get in rv_up - everything else is removed
-		ivec valid_ids = rv.findself_ids ( rv_up );
-		RV rv_hist = rv.subselect ( find ( valid_ids >= 0 ) ); // select only rvs that are in rv_up
-		RV rv_hist0 = rv_hist.remove_time(); // these RVs will form history at time =0
-		// now we need to know what is needed from Up
-		rv_hist = rv_hist.expand_delayes(); // full regressor - including time 0
-		Hrv = rv_hist.subt ( rv_hist0 );   // remove time 0
-		history = zeros ( Hrv._dsize() );
-
-		// decide if we need to copy val to history
-		if ( Hrv._dsize() > 0 ) {
-			v2h_up = rv_hist0.dataind ( rv_up ); // indeces of elements of rv_up to be copied
-		} // else v2h_up is empty
-
-		Hrv.dataind ( rv, h2v_hist, h2v_down );
-
-		downsize = v2v_down.length() + h2v_down.length();
-		upsize = v2v_up.length();
-	}
+	void set_connection ( const RV &rv, const RV &rv_up );
+	
 	//! set history of variable given by \c rv1 to values of \c hist.
-	void set_history ( const RV& rv1, const vec &hist0 ) {
-		bdm_assert ( rv1._dsize() == hist0.length(), "hist is not compatible with given rv1" );
-		ivec ind_H;
-		ivec ind_h0;
-		Hrv.dataind ( rv1, ind_H, ind_h0 ); // find indeces of rv in
-		set_subvector ( history, ind_H, hist0 ( ind_h0 ) ); // copy given hist to appropriate places
-	}
+	void set_history ( const RV& rv1, const vec &hist0 );
 };
 
@@ -1060,27 +952,7 @@
 
 	//! Register DS for logging into logger L
-	virtual void log_register ( logger &L,  const string &prefix ) {
-		bdm_assert ( ytsize == Yrv._dsize(), "invalid DS: ytsize (" + num2str ( ytsize ) + ") different from Drv " + num2str ( Yrv._dsize() ) );
-		bdm_assert ( utsize == Urv._dsize(), "invalid DS: utsize (" + num2str ( utsize ) + ") different from Urv " + num2str ( Urv._dsize() ) );
-
-		root::log_register ( L, prefix );
-		//we know that
-		if ( log_level > 0 ) {
-			logrec->ids.set_size ( 2 );
-			logrec->ids ( 0 ) = logrec->L.add_vector ( Yrv, prefix );
-			logrec->ids ( 1 ) = logrec->L.add_vector ( Urv, prefix );
-		}
-	}
+	virtual void log_register ( logger &L,  const string &prefix );
 	//! Register DS for logging into logger L
-	virtual void log_write ( ) const {
-		if ( log_level > 0 ) {
-			vec tmp ( Yrv._dsize() + Urv._dsize() );
-			getdata ( tmp );
-			// d is first in getdata
-			logrec->L.log_vector ( logrec->ids ( 0 ), tmp.left ( Yrv._dsize() ) );
-			// u follows after d in getdata
-			logrec->L.log_vector ( logrec->ids ( 1 ), tmp.mid ( Yrv._dsize(), Urv._dsize() ) );
-		}
-	}
+	virtual void log_write ( ) const;
 	//!access function
 	virtual const RV& _drv() const {
@@ -1245,18 +1117,5 @@
 
 	//! Set boolean options from a string, recognized are: "logbounds,logll"
-	virtual void set_options ( const string &opt ) {
-		if ( opt.find ( "logfull" ) != string::npos ) {
-			const_cast<epdf&> ( posterior() ).set_log_level ( 10 ) ;
-		} else {
-			if ( opt.find ( "logbounds" ) != string::npos ) {
-				const_cast<epdf&> ( posterior() ).set_log_level ( 2 ) ;
-			} else {
-				const_cast<epdf&> ( posterior() ).set_log_level ( 1 ) ;
-			}
-			if ( opt.find ( "logll" ) != string::npos ) {
-				log_level = 1;
-			}
-		}
-	}
+	virtual void set_options ( const string &opt );
 
 	//! Add all logged variables to a logger
@@ -1264,21 +1123,9 @@
 	//!  * y = 0/1 log-likelihood is to be logged
 	//!  * x = level of the posterior (typically 0/1/2 for nothing/mean/bounds)
-	virtual void log_register ( logger &L, const string &prefix = "" ) {
-		root::log_register ( L, prefix );
-
-		const_cast<epdf&> ( posterior() ).log_register ( L, prefix + L.prefix_sep() + "apost" );
-
-		if ( ( log_level ) > 0 ) {
-			logrec->ids.set_size ( 1 );
-			logrec->ids ( 0 ) = L.add_vector ( RV ( "", 1 ), prefix + L.prefix_sep() + "ll" );
-		}
-	}
+	virtual void log_register ( logger &L, const string &prefix = "" );
+
 	//! Save results to the given logger, details of what is stored is configured by \c LIDs and \c options
-	virtual void log_write ( ) const {
-		posterior().log_write();
-		if ( log_level > 0 ) {
-			logrec->L.logit ( logrec->ids ( 0 ), ll );
-		}
-	}
+	virtual void log_write ( ) const;
+
 	//!@}
 	void from_setting ( const Setting &set ) {
Index: library/bdm/base/datasources.h
===================================================================
--- library/bdm/base/datasources.h (revision 737)
+++ library/bdm/base/datasources.h (revision 738)
@@ -171,16 +171,8 @@
 
 public:
-	void step() {
-		yt2rgr.store_data ( yt ); // y is now history
-		ut2rgr.filldown ( ut, rgr );
-		yt2rgr.filldown ( yt, rgr );
-		yt = ipdf->samplecond ( rgr );
-		ut2rgr.store_data ( ut ); //u is now history
-	}
-	void getdata ( vec &dt_out ) const {
-		bdm_assert_debug ( dt_out.length() >= utsize + ytsize, "Short output vector" );
-		dt_out.set_subvector ( 0, yt );
-		dt_out.set_subvector ( ytsize, ut );
-	}
+	void step();
+
+	void getdata ( vec &dt_out ) const;
+
 	void write ( const vec &ut0 ) {
 		ut = ut0;
@@ -350,20 +342,5 @@
 	}
 
-	virtual void step() {
-		vec imc ( IM->dimensionc() );
-		imc.set_subvector ( 0, xt );
-		u2imc.filldown ( ut, imc );
-		xt = IM->samplecond ( imc );
-
-		vec omc ( OM->dimensionc() );
-		omc.set_subvector ( 0, xt );
-		u2omc.filldown ( ut, omc );
-		vec yt;
-		yt = OM->samplecond ( omc );
-		//fill all data
-		dt.set_subvector ( 0, yt );
-		dt.set_subvector ( yt.length(), xt );
-		dt.set_subvector ( ytsize, ut );
-	}
+	virtual void step();
 
 	//! set parameters
Index: library/bdm/base/bdmbase.cpp
===================================================================
--- library/bdm/base/bdmbase.cpp (revision 737)
+++ library/bdm/base/bdmbase.cpp (revision 738)
@@ -251,4 +251,15 @@
 }
 
+RV RV::expand_delayes() const {
+	RV rvt = this->remove_time(); //rv at t=0
+	RV tmp = rvt;
+	int td = mint();
+	for ( int i = -1; i >= td; i-- ) {
+		rvt.t_plus ( -1 );
+		tmp.add ( rvt ); //shift u1
+	}
+	return tmp;
+}
+
 str RV::tostr() const {
 	ivec idlist ( dsize );
@@ -323,4 +334,20 @@
 }
 
+std::string RV::scalarname ( int scalat ) const {
+	bdm_assert ( scalat < dsize, "Wrong input index" );
+	int id = 0;
+	int scalid = 0;
+	while ( scalid + SIZES ( ids ( id ) ) <= scalat )  {
+		scalid += SIZES ( ids ( id ) );
+		id++;
+	};
+	//now id is the id of variable of interest
+	if ( size ( id ) == 1 )
+		return  NAMES ( ids ( id ) );
+	else
+		return  NAMES ( ids ( id ) ) + "_" + num2str ( scalat - scalid );
+
+}
+
 ivec RV::findself ( const RV &rv2 ) const {
 	int i, j;
@@ -398,4 +425,162 @@
 }
 
+int logger::add_vector ( const RV &rv, string prefix ) {
+	int id;
+	if ( rv._dsize() > 0 ) {
+		id = entries.length();
+		names = concat ( names, prefix ); // diff
+		entries.set_length ( id + 1, true );
+		entries ( id ) = rv;
+	} else {
+		id = -1;
+	}
+	return id; // identifier of the last entry
+}
+
+int logger::add_setting ( const string &prefix ) {
+	Setting &root = setting_conf.getRoot();
+	int id = root.getLength(); //root must be group!!
+	if ( prefix.length() > 0 ) {
+		settings.set_length ( id + 1, true );
+		settings ( id ) = &root.add ( prefix, Setting::TypeList );
+	} else {
+		id = -1;
+	}
+	return id;
+}
+
+void epdf::log_register ( logger &L, const string &prefix ) {
+	RV r;
+	if ( isnamed() ) {
+		r = _rv();
+	} else {
+		r = RV ( "", dimension() );
+	};
+	root::log_register ( L, prefix );
+
+	// log full data
+	if ( log_level == 10 ) {
+		logrec->ids.set_size ( 1 );
+		logrec->ids ( 0 ) = logrec->L.add_setting ( prefix );
+	} else {
+		// log only
+		logrec->ids.set_size ( 3 );
+		if ( log_level > 0 ) {
+			logrec->ids ( 0 ) = logrec->L.add_vector ( r, prefix + logrec->L.prefix_sep() + "mean" );
+		}
+		if ( log_level > 1 ) {
+			logrec->ids ( 1 ) = logrec->L.add_vector ( r, prefix + logrec->L.prefix_sep() + "lb" );
+			logrec->ids ( 2 ) = logrec->L.add_vector ( r, prefix + logrec->L.prefix_sep() + "ub" );
+		}
+	}
+}
+
+void epdf::log_write() const {
+	if ( log_level == 10 ) {
+		to_setting ( logrec->L.log_to_setting ( logrec->ids ( 0 ) ) );
+	} else {
+		if ( log_level > 0 ) {
+			logrec->L.log_vector ( logrec->ids ( 0 ), mean() );
+		}
+		if ( log_level > 1 ) {
+			vec lb;
+			vec ub;
+			qbounds ( lb, ub );
+			logrec->L.log_vector ( logrec->ids ( 1 ), lb );
+			logrec->L.log_vector ( logrec->ids ( 2 ), ub );
+		}
+	}
+}
+
+void datalink_buffered::set_connection ( const RV &rv, const RV &rv_up ) {
+	// create link between up and down
+	datalink_part::set_connection ( rv, rv_up.remove_time() ); // only non-delayed version
+
+	// create rvs of history
+	// we can store only what we get in rv_up - everything else is removed
+	ivec valid_ids = rv.findself_ids ( rv_up );
+	RV rv_hist = rv.subselect ( find ( valid_ids >= 0 ) ); // select only rvs that are in rv_up
+	RV rv_hist0 = rv_hist.remove_time(); // these RVs will form history at time =0
+	// now we need to know what is needed from Up
+	rv_hist = rv_hist.expand_delayes(); // full regressor - including time 0
+	Hrv = rv_hist.subt ( rv_hist0 );   // remove time 0
+	history = zeros ( Hrv._dsize() );
+
+	// decide if we need to copy val to history
+	if ( Hrv._dsize() > 0 ) {
+		v2h_up = rv_hist0.dataind ( rv_up ); // indeces of elements of rv_up to be copied
+	} // else v2h_up is empty
+
+	Hrv.dataind ( rv, h2v_hist, h2v_down );
+
+	downsize = v2v_down.length() + h2v_down.length();
+	upsize = v2v_up.length();
+}
+
+void datalink_buffered::set_history ( const RV& rv1, const vec &hist0 ) {
+	bdm_assert ( rv1._dsize() == hist0.length(), "hist is not compatible with given rv1" );
+	ivec ind_H;
+	ivec ind_h0;
+	Hrv.dataind ( rv1, ind_H, ind_h0 ); // find indeces of rv in
+	set_subvector ( history, ind_H, hist0 ( ind_h0 ) ); // copy given hist to appropriate places
+}
+
+void DS::log_register ( logger &L,  const string &prefix ) {
+	bdm_assert ( ytsize == Yrv._dsize(), "invalid DS: ytsize (" + num2str ( ytsize ) + ") different from Drv " + num2str ( Yrv._dsize() ) );
+	bdm_assert ( utsize == Urv._dsize(), "invalid DS: utsize (" + num2str ( utsize ) + ") different from Urv " + num2str ( Urv._dsize() ) );
+
+	root::log_register ( L, prefix );
+	//we know that
+	if ( log_level > 0 ) {
+		logrec->ids.set_size ( 2 );
+		logrec->ids ( 0 ) = logrec->L.add_vector ( Yrv, prefix );
+		logrec->ids ( 1 ) = logrec->L.add_vector ( Urv, prefix );
+	}
+}
+
+void DS::log_write ( ) const {
+	if ( log_level > 0 ) {
+		vec tmp ( Yrv._dsize() + Urv._dsize() );
+		getdata ( tmp );
+		// d is first in getdata
+		logrec->L.log_vector ( logrec->ids ( 0 ), tmp.left ( Yrv._dsize() ) );
+		// u follows after d in getdata
+		logrec->L.log_vector ( logrec->ids ( 1 ), tmp.mid ( Yrv._dsize(), Urv._dsize() ) );
+	}
+}
+
+void BM::set_options ( const string &opt ) {
+	if ( opt.find ( "logfull" ) != string::npos ) {
+		const_cast<epdf&> ( posterior() ).set_log_level ( 10 ) ;
+	} else {
+		if ( opt.find ( "logbounds" ) != string::npos ) {
+			const_cast<epdf&> ( posterior() ).set_log_level ( 2 ) ;
+		} else {
+			const_cast<epdf&> ( posterior() ).set_log_level ( 1 ) ;
+		}
+		if ( opt.find ( "logll" ) != string::npos ) {
+			log_level = 1;
+		}
+	}
+}
+
+void BM::log_register ( logger &L, const string &prefix ) {
+	root::log_register ( L, prefix );
+
+	const_cast<epdf&> ( posterior() ).log_register ( L, prefix + L.prefix_sep() + "apost" );
+
+	if ( ( log_level ) > 0 ) {
+		logrec->ids.set_size ( 1 );
+		logrec->ids ( 0 ) = L.add_vector ( RV ( "", 1 ), prefix + L.prefix_sep() + "ll" );
+	}
+}
+
+void BM::log_write ( ) const {
+	posterior().log_write();
+	if ( log_level > 0 ) {
+		logrec->L.logit ( logrec->ids ( 0 ), ll );
+	}
+}
+
 void BM::bayes_batch ( const mat &Data, const vec &cond ) {
 	for ( int t = 0; t < Data.cols(); t++ ) {
@@ -403,4 +588,5 @@
 	}
 }
+
 void BM::bayes_batch ( const mat &Data, const mat &Cond ) {
 	for ( int t = 0; t < Data.cols(); t++ ) {
@@ -408,3 +594,4 @@
 	}
 }
-}
+
+}
Index: library/bdm/base/datasources.cpp
===================================================================
--- library/bdm/base/datasources.cpp (revision 737)
+++ library/bdm/base/datasources.cpp (revision 738)
@@ -40,4 +40,35 @@
 	time = 0;
 	Data = Dat;
+}
+
+void PdfDS::step() {
+	yt2rgr.store_data ( yt ); // y is now history
+	ut2rgr.filldown ( ut, rgr );
+	yt2rgr.filldown ( yt, rgr );
+	yt = ipdf->samplecond ( rgr );
+	ut2rgr.store_data ( ut ); //u is now history
+}
+
+void PdfDS::getdata ( vec &dt_out ) const {
+	bdm_assert_debug ( dt_out.length() >= utsize + ytsize, "Short output vector" );
+	dt_out.set_subvector ( 0, yt );
+	dt_out.set_subvector ( ytsize, ut );
+}
+
+void StateDS::step() {
+	vec imc ( IM->dimensionc() );
+	imc.set_subvector ( 0, xt );
+	u2imc.filldown ( ut, imc );
+	xt = IM->samplecond ( imc );
+
+	vec omc ( OM->dimensionc() );
+	omc.set_subvector ( 0, xt );
+	u2omc.filldown ( ut, omc );
+	vec yt;
+	yt = OM->samplecond ( omc );
+	//fill all data
+	dt.set_subvector ( 0, yt );
+	dt.set_subvector ( yt.length(), xt );
+	dt.set_subvector ( ytsize, ut );
 }
 
