Implemented max height calculation