3967: Move determining remove_excess_str into its own function
3967: Use min/max where possible