It's probably worth nitpicking a bit more on this function (and the dependent functions) to make sure we have the simplest solution. But I'll let @gtorodelvalle do this part :)