Move residuetype handling to its own file.