Do more refactoring of OS specific code in compat file.