Assorted bug fixes
Merge pull request #14 from ziyingc/master

Assorted bug fixes