Improve the gallery get_fraction function.