Refactor OS detection code.