Improve width and height detection.