Fixed #4 and #7

Code refactoring and fix issues #4 and #7