Minor corrections

Some missing "var" declaration
Factorising recurrent computation.