Read and write train functions added.