Major refactoring and optimization
Merge pull request #1 from adykto/master

Major refactoring and optimization