tail recursiveness fixed