Code:  Refactoring and minor fixes.
Merge pull request #34 from am11/master

Code:  Refactoring and minor fixes