Merge in deadknight's changes from branch on nloko.