Backport fixes from Toptal