Improved splitting to use longer side if needed.