Implementing data IO and cleaning up.