Refactored Caculate height