Refactored: Separated code into Read and Write submodules.  Added test cases.