Replaced coalesce with updated (working) function. Taken from https://github.com/krlmlr/kimisc