Finish backward and forward algorithms