add implmentation of backward algorithm.