Minor optimizations and bug fixes
Merge pull request #60 from d10/master

Minor optimizations and bug fixes.