refactor Forward and Backward probability implementation