add some tests
fix flush
backward compatibility
improve error handling
Merge pull request #9 from mkdgs/master

update