works factorial function, all variables are global