implement backward algorithm