Move conversion code into a main function