Build fixes

Various build fixes. See commit messages and issue #1 for details.