Attempt to rebase changes from ni-:master

I tried to resolve some of the conflicts for merging with master. Might still need another round once these changes are incorporated.