io code cleanup and test
Merge pull request #12 from stanfy/io-cleanup

io code cleanup and test