Finalize train code.