Improved validation for dimensions.