updated code to calculate the height correctly and removed unused code