Forward algorithm works perfectly