update height calculation method with iteration instead of recursion