wroking on backward algorithm