Commit 19c06e72 removed setting dpy, but it is still used in the NewKDM and OldKDM code branches. So set it again, and add a check that it's not empty where relevant.