improve height calculation