Refactor fd platform specific code