add basic support for file output
add a few more asserts
Merge pull request #8 from zhemao/master

Add basic support for file output