Reorganize and split out platform specific code.