bugfixes and optimizations
Merge pull request #19 from tx2z/master

bugfixes and optimizations