Merge cf code

This PR contains a number of miscellaneous fixes remaining after merging the issue-327 and issue-326 code. Don't merge until after 326 and 327 are merged.

This PR will essentially finish the mass import of Neil's work on the CF build. Some issues remain but they will be dealt with individually.