Refactoring and fixing issue #7.