Code optimizations + cleanup
Bug fixes
Merge pull request #94 from mshamash/master

Bug fixes, cleanup, code optimization.