This is really ugly. I'd like to see an alternative implementation that doesn't use `_.chain` to see if it leads to more readable code.