A lot of cleanup/fixes to get work on Unix systems