More cleanup.

Moved 'final' code (for *nix) into its own function.