Move conversion and detection logic into their own files.