Fixes #3289: Initial pass of refactoring for UNIX compatibility