Implemented forward backward algorithms