some performance changes
Merge pull request #52 from madpew/optimize

some performance changes to fix issue #51