Duncan's bugfixes/work

Don't merge yet.