Improved height calculation