calculate height more intelligently